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: 2541 Location: Silicon Valley




I think something like this:
The range is 24 (6036)
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: 2000 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(argument1) 
argument1
If argument1 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 argument1, a new sequence of pseudorandom numbers is started.
If the first reference to this function in the run unit does not specify argument1, the seed value used will be zero.
In each case, subsequent references without specifying argument1 return the next number in the current sequence.
The returned value is exclusively between zero and one.

Code: 
NEWNUMBER = 36 + (60  36) * (FUNCTION RANDOM) 
or (to include the upper value 60 as possible choice):
Code: 
NEWNUMBER = 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 


