Wow! Thanks for the great info Buck. I'll have to remember to hunt down
this post if I need to build a random number. I do have one question
though.
Buck wrote on 04/04/2007 13:31:36:
One formula that can help is:
callp ceeran0(seed: float: *omit)
rnd = (%dech(float:63:62) * max) + 1
The %DECH converts the float to a number that has a real lot of decimal
places, which preserves as much of the original distribution of the
floats as possible. Multiplying it by the maximum number (10) will
scale that tiny decimal between 0 and (almost) MAX. Adding 1 will move
the entire scaled range up one full integer from 1 to MAX.
This is all you need if your range is between 1 and some other positive
integer. If you need a different minimum, you'll need to throw away
numbers lower than any returned by this algorithm and generate a new
one.
I'm not sure what you mean by that last sentence. Generate a new
algorithm? Generate numbers until I get one in the range I want?
I think a slight modification to the above would give an arbitrary range
[min,max]. I think min and max have to be integers for this to work.
callp ceeran0(seed: float: *omit)
rnd = (%dech(float:63:62) * (max-min + 1))
rnd = rnd + min
Let x = (%dech(float:63:62) * (max-min + 1))
If max = 15 and min = 5, we have
x = (%dech(float:63:62) * (15-5 + 1))
= (%dech(float:63:62) * (11))
= [0,10] after truncation occurs, where [x,y] is the range of numbers
x-y, including x and y.
Now, we have
rnd = [0,10] + min
= [0,10] + 5
= [5,15]
I think that should work unless I've missed something in terms of
intermediate precision.
HTH,
Adam
Attention:
The information contained in this message and or attachments is
intended only for the person or entity to which it is addressed and may contain
confidential and/or privileged material. Any review, retransmission,
dissemination or other use of, or taking of any action in reliance upon, this
information by persons or entities other than the intended recipient is
prohibited. If you received this message in error, please contact the sender
and
delete the material from any system and destroy any copies. Thank you for your
time and consideration.
Attention:
Le contenu de ce message et(ou) les fichiers ci-joints s?adressent
exclusivement à la personne ou -entité à laquelle ils sont destinés. Ils
peuvent
contenir de l?information confidentielle, protégée et(ou) classifiée. Il est
strictement interdit à toute personne ou entité autre que le(la) destinataire
prévu(e) de ce message d?examiner, de réviser, de retransmettre ou de diffuser
cette information, de prendre une quelconque action en fonction ou sur la base
de celle-ci, ou d?en faire tout autre usage. Si vous avez reçu ce message par
erreur, veuillez communiquer avec l?expéditeur(trice), supprimer ce message et
les fichiers ci-inclus de tout système, et en détruire toutes copies, qu?elles
soient électroniques ou imprimées. Nous vous remercions de votre entière
collaboration.
As an Amazon Associate we earn from qualifying purchases.