0

I'm using a node.js client application to fuzz a remote server.

I can ~100% of the time crash the remote server when using Math.random in the node.js client. However, I've since tried a couple of deterministic, seeded random number generators, and neither are able to crash it.

I suspect its due to an idiosyncrasy of Math.random or the seeded generators I've tested.

This is one of the seeded generators I've tried:

var x = 123456789, y = 362436069, z = 521288629, w = 88675123;
function random() { // See http://stackoverflow.com/a/6275875
    var t;
    t = x ^ (x << 11);
    x = y; y = z; z = w;
    return (w = w ^ (w >> 19) ^ (t ^ (t >> 8)))/(4294967296/2);
}

In what way will the output be different to Math.random()? Also, why does 2^32, 4294967296, need to be divided by 2?

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Max
  • 2,760
  • 1
  • 28
  • 47
  • 3
    `Math.random` crashes the server? You sure have some other issues – huysentruitw Jan 10 '14 at 09:22
  • @WouterHuysentruit I know, but to debug the server, I'd ideally like a deterministic test case. Hence trying to have deterministic "random" numbers. – Max Jan 10 '14 at 09:23
  • 1
    I'm almost sure it's not the code inside the generator that will crash the server, it will be the effect of the return value to the rest of your code. So a simple `for`-loop, iterating all possible values between 0 and 1.0 should be enough to crash it too. – huysentruitw Jan 10 '14 at 09:26
  • Can you show us the code that's using the random number? Unless you've overwritten `Math.random` (Which'd be a **very** stupid thing to do), I doubt it's that specific function crashing the server. – Cerbrus Jan 10 '14 at 09:29

1 Answers1

0

In what way will the output be different to Math.random()?

Math.random uses an implicit engine specific algorithm which has no seeding capability, whereas your implementation is platform independent and explicitly seeded.

Also, why does 2^32, 4294967296, need to be divided by 2?

It is used to ensure a multiple of two, so the random number generator does not fail on an odd number.

References

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265