davidbau / seedrandom

seeded random number generator for Javascript
2.04k stars 160 forks source link

Question #8

Closed psypersky closed 10 years ago

psypersky commented 10 years ago

Hello davidbau, great lib.

I'm adding noise to a graph and i need to be the same any time i run the script, the only thing is that i need to jump values when the graph is too long, for example:

Math.seedrandom('test');
console.log(Math.random());  // 0.8722025543160253 
console.log(Math.random());  // 0.4023928518604753 
console.log(Math.random());  // 0.9647289658507073
console.log(Math.random());  // 0.30479896375101545 
//... Then i get a lot more

I need to do something like

Math.seedrandom('test'); Math.skipRandoms(3); console.log(Math.random()); // 0.30479896375101545

Is something like this possible?

Thanks for this awesome lib :+1:

davidbau commented 10 years ago

Hey there - the method for skipping randoms is just to write your own loop and skip them. Actually I think that there is likely no shortcut for "skipping through RC4", which is the underlying generator - your best bet is to just run the generator for the number of times you want to skip.