[REBOL] [style] Feeling REBOLish (was: Notes on seeding 'random/seed)
From: reboler::programmer::net at: 22-Mar-2004 21:21
Good stuff, Gregg!
I like yours better with two exceptions...
randomize: func [
"Reseed the random number generator with 'now/precise."
/with seed [date! time! integer!] "Enter your own seed."
][
random/seed any [seed to-integer checksum/secure form now/precise]
]
It is more REBOLish to have an explicit refinement (just like 'random and 'random/seed),
so this
is a definite improvement.
Replacing 'either with 'any is also an improvement.
Part of the whole problem with 'random/seed in the first place is that there was not
enough
detail given to know the type of arguments accepted. I want to be specific about the
usage _and_
the implementation. The user should know _explicitly_ what the seed is when the user
asks for
help (and not just when the user goes to the source i.e. >>source randomize).
This info is often lacking in REBOL functions, especially natives.
>> help randomize
USAGE:
RANDOMIZE /with seed
DESCRIPTION:
Reseed the random number generator with 'now/precise.
RANDOMIZE is a function value.
REFINEMENTS:
/with
seed -- Enter your own seed. (Type: date time integer)
.... versus ...
>> help random
USAGE:
RANDOM value /seed /secure /only
DESCRIPTION:
Returns a random value of the same datatype.
RANDOM is an action value.
ARGUMENTS:
value -- Maximum value of result (Type: any)
REFINEMENTS:
/seed -- Restart or randomize ;<<!!! NO INFORMATION GIVEN!
/secure -- Returns a cryptographically secure random number.
/only -- Return single value from series.
The user should also be able to enter their _own_ seed without any processing by the
function
itself. Thus the user needs to know what data types are accepted.
These changes tell the user all he needs to know about using 'randomize.
Just my $0.02.
Gregg, thanks for your time and interest. Amazing how many ways to skin the cat.
Follow-up: Do you think that I should send REBOL feedback on the fact that 'random/seed
does
not use sub-second precision? IMHO, I think this should be considered a bug in 'random.
--
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm