jscl
jscl copied to clipboard
Random not implemented
The RANDOM function, MAKE-RANDOM-STATE, etc are not implemented.
I think RANDOM could probably just be a thin wrapper around javascript's Math.random()?
Unfortunately default Javascript random generator cannot be seeded, so to support random state functions a custom pseudorandom generator will have to be used.
On Mon, Apr 29, 2013 at 1:48 PM, RadioTelescope [email protected]:
The RANDOM function, MAKE-RANDOM-STATE, etc are not implemented.
I think RANDOM could probably just be a thin wrapper around javascript's Math.random()?
— Reply to this email directly or view it on GitHubhttps://github.com/davazp/jscl/issues/52 .
Oh, that's unfortunate.
So, here's a potentially crazy idea: most programs that use random numbers just (setf *random-state* (make-random-state t))
at the top and then call random
wherever it's needed, right? What if we made (make-random-state t)
return a magic value that tells the CL random to use JS Math.random(). We could still implement a mersenne twister PRNG that works the normal way when *random-state*
is set to something other than the magic value.
No you cannot in general. Random state can be copied so if you start using Javascript random you must also start storing all random numbers extracted after the first copy of the state is made. Not sure if this is worth the effort... probably just implementing or getting somewhere a decent random is better. By the way in the past I've been facing truly horrible random generators in javascript so there's nothing much worth to save. My nexus 1 random generator is so bad that's unusable even for random shuffling songs... it was the same in Chrome, but they fixed Chrome and left android broken; see http://stackoverflow.com/questions/5531827/random-point-on-a-given-sphere
Okay fair enough. I'll just implement a simple version of the algorithm sbcl uses then. On Apr 29, 2013 3:51 PM, "Andrea Griffini" [email protected] wrote:
No you cannot in general. Random state can be copied so if you start using Javascript random you must also start storing all random number extracted at the first copy is made. Not sure if this is worth the effort... probably just implementing or just getting somewhere a decent random is better. By the way in the past I've been facing truly horrible random generators in javascript so there's nothing much worth to save. My nexus 1 random generator is so bad that's unusable even for random shuffling songs... it was the same in Chrome, but they fixed Chrome and left android broken; see http://stackoverflow.com/questions/5531827/random-point-on-a-given-sphere
— Reply to this email directly or view it on GitHubhttps://github.com/davazp/jscl/issues/52#issuecomment-17189841 .
It is very unfortunate, but there are a few things like this. For example, sleep
will not be possible either I guess.
Would a member of the PCG family be sufficient for this, or do we demand cryptographic security from the generator also?
@equwal I'm not familiar with random number generators but, I would say that it should be sufficient. If you want something secure you can FFI to some JS library. (We can do that for the standard functions as well).