Random Number
am 09.01.2008 20:07:42 von Railman
I am trying to generate a random number between 1000 and 5000. I am using
round((random * 10000);0)
I get my number, but often it is below 1000 and above 5000. Is there a
way to set the high and low limits.
Re: Random Number
am 09.01.2008 20:38:12 von Jens Teich
Ron Lambert writes:
> I am trying to generate a random number between 1000 and 5000. I am using
> round((random * 10000);0)
> I get my number, but often it is below 1000 and above 5000. Is there
> a way to set the high and low limits.
First genarate a random number between 0 and 4000, then add 1000.
-jens
Re: Random Number
am 09.01.2008 20:45:10 von Gregory Weston
In article <2008010913074275249-railman@sasktelnet>,
Ron Lambert wrote:
> I am trying to generate a random number between 1000 and 5000. I am using
> round((random * 10000);0)
> I get my number, but often it is below 1000 and above 5000. Is there a
> way to set the high and low limits.
Generate a random number, multiple it by 4000, truncate it, and add 1000.
Re: Random Number
am 09.01.2008 21:03:50 von Helpful Harry
In article <2008010913074275249-railman@sasktelnet>, Ron Lambert
wrote:
> I am trying to generate a random number between 1000 and 5000. I am using
> round((random * 10000);0)
> I get my number, but often it is below 1000 and above 5000. Is there a
> way to set the high and low limits.
The forumla for generating a "random" number (computers cannot generate
truely random numbers) in any programming language / application is
always something like:
Tuncate(Random * (UpperLimit - LowerLimit) + LowerLimit, 0)
This is the FileMaker version - the names and formats of the functions
may vary depending on what application you're using, but the
mathematical approach is the same:
- the Random function returns a "random" number between 0 and 1
- multiply that by the difference between you limits and you
get a "random" number between 0 and "UpperLimit - LowerLimit"
(in your case that is between 0 and 4000).
- add the lower limit to raise the "random number to between
LowerLimit and UpperLimit (in you case adding 1000 gives you
a "random" number between 1000 and 5000).
Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)
Re: Random Number
am 10.01.2008 00:32:16 von Railman
> Tuncate(Random * (UpperLimit - LowerLimit) + LowerLimit, 0)
>
> Helpful Harry
> Hopefully helping harassed humans happily handle handiwork hardships
thanks
--
A second cup of coffee always works for me.
Re: Random Number
am 10.01.2008 12:14:26 von unknown
Post removed (X-No-Archive: yes)
Re: Random Number
am 11.01.2008 00:50:09 von Helpful Harry
In article , Martin
Trautmann wrote:
> On Thu, 10 Jan 2008 09:03:50 +1300, Helpful Harry wrote:
> > The forumla for generating a "random" number (computers cannot generate
> > truely random numbers) in any programming language / application is
> > always something like:
> >
> > Tuncate(Random * (UpperLimit - LowerLimit) + LowerLimit, 0)
>
> ... and it is always the question whether this will return the upper and
> lower limits at all and with the same probability as any value in
> between.
>
> Example:
> UpperLimit = 5000
> LowerLimit = 1000
>
> Let's assume that random will return numbers from 0/10000 = 0 up to
> 10000/10000 = 1
>
> 1/10 0000 result
> 0 1000
> 1 1000
> 2 1000
>
> 3 1001
> 4 1001
>
> 5 1002
> 6 1002
> 7 1002
>
> ... that's ok, since this will be smoothed by a higher precision of the
> random steps
>
> But:
> 9993 4997
> 9994 4997
>
> 9995 4998
> 9996 4998
> 9997 4998
>
> 9998 4999
> 9999 4999
>
> 10000 5000
>
> You see that truncate will reduce the probability of the highest value.
> You might fix this by using "round" instead of truncate - but this will
> slightly increase the probablity of the highest value and decrease the
> smallest value.
>
> Better might be to do a
> int(random * (1 + UpperLimit - LowerLimit) + LowerLimit)
> ... which may require an extra check and fix to prevent the number
> UpperLimit + 1 ...
All true ... in fact most "Random" / "Rand" functions don't actually
reach "1" anyway. They generate a number from 0 to 0.99999999999.
FileMaker 5.5's Help is unclear about what it really generates. Excel's
Help defines it much better as:
RAND
Returns an evenly distributed random number greater than or
equal to 0 and less than 1. A new random number is returned
every time the worksheet is calculated.
This "less than 1" itself means if you actually want the UpperLimit
included as a possible result then the extra "+ 1" should be added to
the calculation, as you have done.
ie.
Tuncate(Random * (1 + UpperLimit - LowerLimit) + LowerLimit, 0)
Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)
Re: Random Number
am 11.01.2008 16:36:45 von ursus.kirk
On a last note let it be clear that "true random" is very hard to come by.
There are even sites where you may download random numbers. Filemaker random
surely doesn't deliver true random, but may be adequate for your wishes.
Keep well, Ursus
Re: Random Number
am 11.01.2008 21:00:26 von Helpful Harry
In article <47878d0b$0$93942$dbd41001@news.wanadoo.nl>, "Ursus"
wrote:
> On a last note let it be clear that "true random" is very hard to come by.
> There are even sites where you may download random numbers. Filemaker random
> surely doesn't deliver true random, but may be adequate for your wishes.
Computers can't generate truely random numbers - they have to be based
on some data, and therefore can be fairly easy to replicate the
sequence. In some applications if you generate "enough" numbers you
find the sequence starts all over again.
Hopefully those downloadable "random" numbers were generated some other
way, although you may still run out if you are needing lots of them.
Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)
Re: Random Number
am 11.01.2008 23:37:49 von ursus.kirk
On the risk of going of topic. Usually random numbers that are generated by
computers are based on a cycle, no matter what you try, but inherent to a
system is the cpu that calculates in cycles per second. The trick is to
start on a seed and never reuse thaty seed again when starting. Like quasar
pulses or static noise. Look into http://www.random.org/ for some info on
free random numbers.
Keep wel, Ursus
"Helpful Harry" schreef in bericht
news:120120080900268952%helpful_harry@nom.de.plume.com...
> In article <47878d0b$0$93942$dbd41001@news.wanadoo.nl>, "Ursus"
> wrote:
>
>> On a last note let it be clear that "true random" is very hard to come
>> by.
>> There are even sites where you may download random numbers. Filemaker
>> random
>> surely doesn't deliver true random, but may be adequate for your wishes.
>
> Computers can't generate truely random numbers - they have to be based
> on some data, and therefore can be fairly easy to replicate the
> sequence. In some applications if you generate "enough" numbers you
> find the sequence starts all over again.
>
> Hopefully those downloadable "random" numbers were generated some other
> way, although you may still run out if you are needing lots of them.
>
> Helpful Harry
> Hopefully helping harassed humans happily handle handiwork hardships ;o)