Random Number within Limits
Author Message
Random Number within Limits

Im attempting to write a program in Modula2 on our VMS system
but have been experiencing difficulty obtaining a Random Number
that falls between certain limits (ie Greater than 0 But less than 21)

I am Importing the Mth\$Random function from the MathematicsProcedures
module and giving it a Seed value that ranged from -100 to 1000 (and Many
Points in Between).  What I get back is always a negative value.

Could someone shed some light on How I could obtain these random numbers.

Thank You

Chris Darrigo

Sat, 03 Sep 1994 09:05:00 GMT
Random Number within Limits

#
# Im attempting to write a program in Modula2 on our VMS system
# but have been experiencing difficulty obtaining a Random Number
# that falls between certain limits (ie Greater than 0 But less than 21)
#
# I am Importing the Mth\$Random function from the MathematicsProcedures
# module and giving it a Seed value that ranged from -100 to 1000 (and Many
# Points in Between).  What I get back is always a negative value.
#
# Could someone shed some light on How I could obtain these random numbers.

Most random-number packages do this by generating a normalized
REAL (in the 0..1 range) and multiplying by the range of the
numbers desired.  This is typically quite slow unless you have
a Cray or similar floating-point oriented machine.

For most of us, it's better to narrow the range of a fast integer
out-of-range numbers.  On the average, you'll only have to toss
half at worst.
--
| The above opinions may not be original, but they are mine and mine alone. |
|        "While it may not be for you to complete the task,                 |
|         neither are you free to refrain from it." -- R. Tarfon            |
+-=-=-    (I wish _this_ were original!)        D. C. Sessions         -=-=-+

Mon, 05 Sep 1994 04:13:43 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages