dbTalk Databases Forums  

random numbers in a specified range

comp.databases.filemaker comp.databases.filemaker


Discuss random numbers in a specified range in the comp.databases.filemaker forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
stabit
 
Posts: n/a

Default random numbers in a specified range - 04-07-2007 , 12:35 PM






Does anyone know how to generate a random number within a specified
range (ex: between 100-200)?
I tried Int(Mod(Random * 100, 200)) but that doesn't work.


Reply With Quote
  #2  
Old   
Ursus
 
Posts: n/a

Default Re: random numbers in a specified range - 04-07-2007 , 01:00 PM







"stabit" <sharon.tabit (AT) gmail (DOT) com> schreef in bericht
news:1175967314.821249.26480 (AT) e65g2000hsc (DOT) googlegroups.com...
Quote:
Does anyone know how to generate a random number within a specified
range (ex: between 100-200)?
I tried Int(Mod(Random * 100, 200)) but that doesn't work.
Really random doesn't exist within Filemakers world.
You might try a calcfield cRandomNum

Let( [ cRandomNum = Int(Random * 100000)];cRandomNum)

Which will return a random between -1 and 99999.

Otr you might try the following calculation

Ceiling( Random * 90000 ) + 9999

This generates only 5 digit numbers (i.e., numbers between 10000 and 99999
inclusive)

Keep well, Ursus




Reply With Quote
  #3  
Old   
manet
 
Posts: n/a

Default Re: random numbers in a specified range - 04-07-2007 , 05:37 PM



stabit <sharon.tabit (AT) gmail (DOT) com> wrote:

Quote:
(ex: between 100-200)
100+100*random

if you need integer, you'l have to take [100 + int (100*random + 0,5)]
--
Philippe Manet


Reply With Quote
  #4  
Old   
Helpful Harry
 
Posts: n/a

Default Re: random numbers in a specified range - 04-07-2007 , 06:03 PM



In article <4617dc36$0$12021$dbd4f001 (AT) news (DOT) wanadoo.nl>, "Ursus"
<ursus.kirk (AT) wanadoo (DOT) nl> wrote:

Quote:
"stabit" <sharon.tabit (AT) gmail (DOT) com> schreef in bericht
news:1175967314.821249.26480 (AT) e65g2000hsc (DOT) googlegroups.com...
Does anyone know how to generate a random number within a specified
range (ex: between 100-200)?
I tried Int(Mod(Random * 100, 200)) but that doesn't work.

Really random doesn't exist within Filemakers world.
You might try a calcfield cRandomNum
"Really random" doesn't exist in any computer programming language,
it's a limitation of the computer itself. In some programming languages
you can get a "more random" number by using the system clock as a
seeding value to start the "random" stream. )



Quote:
You might try a calcfield cRandomNum

Let( [ cRandomNum = Int(Random * 100000)];cRandomNum)

Which will return a random between -1 and 99999.
Snip

Errr... the Random function returns a number between 0 and 1, so that
calculation above will return a "random" number between 0 and 100000.


The usual programming solution to obtain a "random" number between
LowerLimit and UpperLimit is:

Int((Random * UpperLimit) + LowerLimit)

In all of these calculations "between" is the important word - you will
never get the Upper Limt or LowerLimit numbers themselves.


Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #5  
Old   
Ursus
 
Posts: n/a

Default Re: random numbers in a specified range - 04-08-2007 , 03:59 AM





Quote:
You might try a calcfield cRandomNum

Let( [ cRandomNum = Int(Random * 100000)];cRandomNum)

Which will return a random between -1 and 99999.
Snip

Errr... the Random function returns a number between 0 and 1, so that
calculation above will return a "random" number between 0 and 100000.

I slightly disagree with that. And to try this I have built a file, just one
field (the calc above). and a script in a loop I generate one million
records (took about 45 minutes). It generated 8 records containing 0.
It generated no reords containing 100000. The highest it got was 99999 and
had 8 records of this as well. Just to satisfy my curiousity, I looked at
some other numbers within the file and noticed thatother amounts also
existed. Like 99998 has 28 occurrances. So it looks like we are both partly
right. The function will generate a number between -1 and 100000.

Keep well, Ursus




Reply With Quote
  #6  
Old   
Michael Myett
 
Posts: n/a

Default Re: random numbers in a specified range - 04-08-2007 , 01:18 PM



stabit wrote:
Quote:
Does anyone know how to generate a random number within a specified
range (ex: between 100-200)?
I tried Int(Mod(Random * 100, 200)) but that doesn't work.

I would use:

100 + Round( Random * ( 200 - 100 ); 0 )



Reply With Quote
  #7  
Old   
Helpful Harry
 
Posts: n/a

Default Re: random numbers in a specified range - 04-08-2007 , 04:02 PM



In article <4618aed7$0$52539$dbd4b001 (AT) news (DOT) wanadoo.nl>, "Ursus"
<ursus.kirk (AT) wanadoo (DOT) nl> wrote:

Quote:
You might try a calcfield cRandomNum

Let( [ cRandomNum = Int(Random * 100000)];cRandomNum)

Which will return a random between -1 and 99999.
Snip

Errr... the Random function returns a number between 0 and 1, so that
calculation above will return a "random" number between 0 and 100000.

I slightly disagree with that. And to try this I have built a file, just one
field (the calc above). and a script in a loop I generate one million
records (took about 45 minutes). It generated 8 records containing 0.
It generated no reords containing 100000. The highest it got was 99999 and
had 8 records of this as well. Just to satisfy my curiousity, I looked at
some other numbers within the file and noticed thatother amounts also
existed. Like 99998 has 28 occurrances. So it looks like we are both partly
right. The function will generate a number between -1 and 100000.

Keep well, Ursus
If you look at your test numbers you will find NONE of them are below
zero.

The Random function only returns a "random" number between 0 and 1, so
multiplying its result by 100000 will mathematically give you a number
between 0 and 100000 ... no negatives are possible with that
calculation.


I was partly wrong though in the bit you snipped off.

I said you won't get the limit points of 0 and 100000 appearing, which
is wrong. The Random function number itself will never give 0 or 1, but
by using the Int function you will get the lower limit of 0 since a
result of 0.4327 will be chopped to just 0. You will never get the
upper limit though. If you want the possibility of getting the 100000
you need to alter the function to be:

Int(Random * 100001)

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
  #8  
Old   
Ursus
 
Posts: n/a

Default Re: random numbers in a specified range - 04-09-2007 , 04:37 AM





Quote:
existed. Like 99998 has 28 occurrances. So it looks like we are both
partly
right. The function will generate a number between -1 and 100000.

Keep well, Ursus

If you look at your test numbers you will find NONE of them are below
zero.

Yes, that is what I said. Between -1 and 100000, or in other words excluding
those values and including 0 and 99999.

Quote:
The Random function only returns a "random" number between 0 and 1, so
multiplying its result by 100000 will mathematically give you a number
between 0 and 100000 ... no negatives are possible with that
calculation.


I was partly wrong though in the bit you snipped off.
See above. And I think that with all this that Stabit (the OP) has more than
enough info to get what he needs.

Keep well, Ursus




Reply With Quote
  #9  
Old   
manet
 
Posts: n/a

Default Re: random numbers in a specified range - 04-09-2007 , 07:06 AM



Helpful Harry <helpful_harry (AT) nom (DOT) de.plume.com> wrote:

Quote:
If you want the possibility of getting the 100000
you need to alter the function to be:

Int(Random * 100001)
this will give a bad distribution favouring biggest numbers (not really
important with 1000001, but significant with 101)
the good way is adding 0.5 or using the "round" function (wich is the
same thing)
--
Philippe Manet


Reply With Quote
  #10  
Old   
Helpful Harry
 
Posts: n/a

Default Re: random numbers in a specified range - 04-09-2007 , 07:22 PM



In article <461a0961$0$97759$dbd41001 (AT) news (DOT) wanadoo.nl>, "Ursus"
<ursus.kirk (AT) wanadoo (DOT) nl> wrote:

Quote:
existed. Like 99998 has 28 occurrances. So it looks like we are both
partly
right. The function will generate a number between -1 and 100000.

Keep well, Ursus

If you look at your test numbers you will find NONE of them are below
zero.

Yes, that is what I said. Between -1 and 100000, or in other words excluding
those values and including 0 and 99999.
Sorry, you're right ... I keep forgetting that there's an Int function
in there as well.

I'll blame not having any Internet access for two days (hopeless ISP!)
giving me lots to try and catch up on and not paying enough attention.


Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.