View previous topic :: View next topic
|
Author |
Message |
Venkata Ramayya
New User
Joined: 03 Dec 2007 Posts: 49 Location: United States
|
|
|
|
Hello,
I have a requirement to generate random number from range of numbers. I know random function can be used, but how I can generate numbers between range. Can anyone share if you built similar logic before?
Example:
Low Range - 36
High Range - 60
I would need to get random numbers between 36 and 60 |
|
Back to top |
|
 |
Pedro
Global Moderator

Joined: 01 Sep 2006 Posts: 2600 Location: Silicon Valley
|
|
|
|
I think something like this:
The range is 24 (60-36)
and assuming the range of a generated random number is something like 0 thru 999 (one thousand possibilities)
1000 / 24 = 41.6666667
and x is a generated random number:
(x / 41.6666667) + 36 =
and then round off the result. |
|
Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2159 Location: USA
|
|
|
|
Pedro wrote: |
and assuming the range of a generated random number is something like 0 thru 999 (one thousand possibilities) |
RANDOM
Quote: |
The RANDOM function returns a numeric value that is a pseudorandom number from a rectangular distribution.
The function type is numeric.
Format
Code: |
FUNCTION RANDOM(argument-1) |
argument-1
If argument-1 is specified, it must be zero or a positive integer. However, only values in the range from zero up to and including 2,147,483,645 yield a distinct sequence of pseudorandom numbers.
If a subsequent reference specifies argument-1, a new sequence of pseudorandom numbers is started.
If the first reference to this function in the run unit does not specify argument-1, the seed value used will be zero.
In each case, subsequent references without specifying argument-1 return the next number in the current sequence.
The returned value is exclusively between zero and one.
|
Code: |
NEW-NUMBER = 36 + (60 - 36) * (FUNCTION RANDOM) |
or (to include the upper value 60 as possible choice):
Code: |
NEW-NUMBER = 36 + (60 - 36 + 1) * (FUNCTION RANDOM) |
|
|
Back to top |
|
 |
Venkata Ramayya
New User
Joined: 03 Dec 2007 Posts: 49 Location: United States
|
|
|
|
Thanks for the response Pedro and sergeyken |
|
Back to top |
|
 |
|