|
Alexander Daguerre
Junior Birdman
Join date: 9 Jun 2004
Posts: 32
|
08-06-2006 04:23
From: Bitzer Balderdash Actually, I strongly suspect that you can use llFrand to create pseudo random numbers.... You're almost certainly correct, of course, most languages just use linear congruential generators and I'd expect LSL to just call through to the underlying C library for something like this. The other thing to watch out for with this function is that because it returns a float, you can't get (much) more than 23 bits of randomness out of it at a time. So don't take the result of an llFrand call, multiply it by 4 billion and think you've got a full-range random channel number.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-06-2006 11:35
From: Alexander Daguerre You're almost certainly correct, of course, most languages just use linear congruential generators and I'd expect LSL to just call through to the underlying C library for something like this. Right. And we can't set a seed in LSL, so we can only really expect it to be RANDOM. It cannot repeat a pseudo-random sequence given a key as seed for example. Might be a nifty feature to ask for though. From: someone The other thing to watch out for with this function is that because it returns a float, you can't get (much) more than 23 bits of randomness out of it at a time. So don't take the result of an llFrand call, multiply it by 4 billion and think you've got a full-range random channel number. Try this: integer rand = (integer)llFrand((float)(1 << 16)) << 16 | (integer)llFrand((float)(1 << 16)); or for only negative numbers: integer negRand = 0x80000000 | (integer)llFrand((float)(1 << 15)) << 16 | (integer)llFrand((float)(1 << 16))
|