Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Some random remarks

0 views
Skip to first unread message

Leopold Toetsch

unread,
Nov 21, 2003, 5:23:31 PM11/21/03
to P6I
Almost forgotten about that, but I've checked in some days ago the base
of Hash randomization, which is basically most of a ?rand48 library.

I don't know if its useful or practically usable with HLL code
generation but I've added to these randon function interface a
how_random parameter, which could mean (in linux-speak):
0 ... internal current functions
1 ... /dev/urandom
2 ... /dev/random
3 ... maybe ultra hardware something

Anyway, we could add some opcodes for this like:

srand Iseed, Ilevel # seed rand for Ilevel
rand Idest, Ilevel # rand from 0..LIMIT
rand Idest, Ifrom, Ito, Ilevel
rand Ndest, Ilevel
rand Sdest, Ilen, Pchar-ranges, Ilevel

where operands are meaning:

Iseed ... some input rand seed
Ilevel ... the how_random level
Ifrom, Ito ... range of returned random ints
Ndest ... random from 0.0 ... 1.0
Sdest ... new random string of len Ilen composed of chars in the
Pchar-ranges ... range array which has from-to pairs

Better proposals & comments welcome,
leo

Matt Fowles

unread,
Nov 22, 2003, 1:40:07 PM11/22/03
to Leopold Toetsch, P6I
All~

We could try to keep the opcode count down by simply having a seed
opcode and an opcode to produce n random bytes... Anyone who wants more
specific ranges could do the modulus and addition themselves.

Matt

Juergen Boemmels

unread,
Nov 24, 2003, 10:03:01 AM11/24/03
to Matt_...@softhome.net, Leopold Toetsch, P6I
Matt Fowles <Matt_...@softhome.net> writes:

> All~
>
> We could try to keep the opcode count down by simply having a seed
> opcode and an opcode to produce n random bytes... Anyone who wants
> more specific ranges could do the modulus and addition themselves.

The modulus/addition trick is very common but actually a bad idea. See
Press et al., Numerical Recipies in C, 2nd ed. or Linux rand(3):
"If you want to generate a random integer between 1
and 10, you should always do it by using high-order
bits, as in

j=1+(int) (10.0*rand()/(RAND_MAX+1.0));

and never by anything resembling

j=1+(rand() % 10);

(which uses lower-order bits)."

The best way to avoid this add/mod trick is to provide a convenient
way to get random numbers in ranges.

I like the basic idea of having different random number
generators. But having only the integer valued level seems a little
bit problematic to me. Its not easy extendable if you have some
special needs on the random number generator.

So I propose something completely new:
Use a PMC.
You don't need any special ops, only a special PMC.
creating a random number generator.
new P0, .RandomNumberGenerator
getting a integervalued random number
set I0, P0
getting a floatvalued random number
set N0, P0

Special versions of the random number generator like other ranges can
be created by initialisation arguments.

Thoughs
boe
--
Juergen Boemmels boem...@physik.uni-kl.de
Fachbereich Physik Tel: ++49-(0)631-205-2817
Universitaet Kaiserslautern Fax: ++49-(0)631-205-3906
PGP Key fingerprint = 9F 56 54 3D 45 C1 32 6F 23 F6 C7 2F 85 93 DD 47

Dan Sugalski

unread,
Nov 24, 2003, 10:14:28 AM11/24/03
to Juergen Boemmels, Matt_...@softhome.net, Leopold Toetsch, P6I
On Mon, 24 Nov 2003, Juergen Boemmels wrote:

> I like the basic idea of having different random number
> generators. But having only the integer valued level seems a little
> bit problematic to me. Its not easy extendable if you have some
> special needs on the random number generator.
>
> So I propose something completely new:
> Use a PMC.

I think this is the way to go. While random numbers aren't quite the swamp
that other things may be there are enough legitimate variations that I'd
rather not weld this one in as an op, except perhaps a "fetch current
random number PMC" op, though that should be hanging off the environmental
query op that gets us the ENV hash PMC, amongst other things.

Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

0 new messages