Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualiMalc

Posted 05 November 2012 - 12:23 PM

I have run into issues with the random number generator that did require calling srand again, but that is rare. Since it is a pseudo-random number generator, patterns can emerge that may be undesirable. If that happens, calling srand will resolve the issue. Chances are you'll never run into such an issue. That being said, alvaro is correct; srand should not be called every time rand is called.

[edit]
I should note that the RNG I was using at the time was limited to 16-bit signed integers.

Unless you intentionally wish to repeat a previous random sequence, calling srand again is undesireable.
Re-seeding causes the period of the PRNG to decrease because you jump to a new point within the sequence. That in itself reduces the amount of randomness.
If re-seeding made it seem less random then that was just dumb luck. It can just as easily make things worse.
The problem you had, with seeing a pattern in the output, is correctly solved by using a better PRNG.


To the OP: It's a common misconception, but the method you are using isn't actually any less biased that just using the modulus operator, it just puts the bias in different places instead of on values at one end of the range. Specific values still always have a slightly higher probability.
Yes you are using the higher bits of the random value, which is good because these are generally more random, but that is still tangential to the issue of the distribution bias introduced by the funnelling of N inputs down to K outputs where gcd(K, N) != 1.

Of course for what you want to use it for, the amount of bias you get is probably not important.

However, if you want to see how to actually remove distribution bias, check out my post #6 here about using the rejection method:
http://cboard.cprogr...etween-x-y.html

#3iMalc

Posted 05 November 2012 - 02:31 AM

I have run into issues with the random number generator that did require calling srand again, but that is rare. Since it is a pseudo-random number generator, patterns can emerge that may be undesirable. If that happens, calling srand will resolve the issue. Chances are you'll never run into such an issue. That being said, alvaro is correct; srand should not be called every time rand is called.

[edit]
I should note that the RNG I was using at the time was limited to 16-bit signed integers.

Unless you intentionally wish to repeat a previous random sequence, calling srand again is undesireable.
Re-seeding causes the period of the PRNG to decrease because you jump to a new point within the sequence. That in itself reduces the amount of randomness.
If re-seeding made it seem less random then that was just dumb luck. It can just as easily make things worse.
The problem you had, with seeing a pattern in the output, is correctly solved by using a better PRNG.


To the OP: It's a common misconception, but the method you are using isn't actually any less biased that just using the modulus operator, it just puts the bias in different places instead of on values at one end of the range. Specific values still always have a slightly higher probability.
Yes you are using the higher bits of the random value, which is good because these are generally more random, but that is still tangential to the issue of the distribution bias introduced by the funnelling of N inputs down to K outputs where gcd(K, N) != 0.

Of course for what you want to use it for, the amount of bias you get is probably not important.

However, if you want to see how to actually remove distribution bias, check out my post #6 here about using the rejection method:
http://cboard.cprogramming.com/c-programming/145187-how-pick-random-number-between-x-y.html

#2iMalc

Posted 05 November 2012 - 02:31 AM

I have run into issues with the random number generator that did require calling srand again, but that is rare. Since it is a pseudo-random number generator, patterns can emerge that may be undesirable. If that happens, calling srand will resolve the issue. Chances are you'll never run into such an issue. That being said, alvaro is correct; srand should not be called every time rand is called.

[edit]
I should note that the RNG I was using at the time was limited to 16-bit signed integers.

Unless you intentionally wish to repeat a previous random sequence, calling srand again is undesireable.
Re-seeding causes the period of the PRNG to decrease because you jump to a new point within the sequence. That in itself reduces the amount of randomness.
If re-seeding made it seem less random then that was just dumb luck. It can just as easily make things worse.
The problem you had, with seeing a pattern in the output, is correctly solved by using a better PRNG.


To the OP: It's a common misconception, but the method you are using isn't actually any less biased that just using the modulus operator, it just puts the bias in different places instead of on values at one end of the range. Specific values still always have a slightly higher probability.
Yes you are using the higher bits of the random value, which is good because these are generally more random, but that is still tangential to the issue of the distribution bias introduced by the funnelling of N inputs down to K outputs where gcd(K, N) != 0.

Of course for what you want to use it for, the amount of bias you get is probably not important.

However, if you want to see how to actually remove distribution bias, check out my post #6 here about using the rejection method:
http://cboard.cprogramming.com/c-programming/145187-how-pick-random-number-between-x-y.html

#1iMalc

Posted 05 November 2012 - 02:31 AM

I have run into issues with the random number generator that did require calling srand again, but that is rare. Since it is a pseudo-random number generator, patterns can emerge that may be undesirable. If that happens, calling srand will resolve the issue. Chances are you'll never run into such an issue. That being said, alvaro is correct; srand should not be called every time rand is called.

[edit]
I should note that the RNG I was using at the time was limited to 16-bit signed integers.

Unless you intentionally wish to repeat a previous random sequence, calling srand again is undesireable.
Re-seeding causes the period of the PRNG to decrease because you jump to a new point within the sequence. That in itself reduces the amount of randomness.
If re-seeding made it seem less random then that was just dumb luck. It can just as easily make things worse.
The problem you had, with seeing a pattern in the output, is correctly solved by using a better PRNG.


To the OP: It's a common misconeption, but the method you are using isn't actually any less biased that just using the modulus operator, it just puts the bias in different places instead of on values at one end of the range. Specific values still always have a slightly higher probability.
Yes you are using the higher bits of the random value, which is good because these are generally more random, but that is still tangential to the issue of the distribution bias introduced by the funnelling of N inputs down to K outputs where gcd(K, N) != 0.

Of course for what you want to use it for, the amount of bias you get is probably not important.

However, if you want to see how to actually remove distribution bias, check out my post #6 here about using the rejection method:
http://cboard.cprogramming.com/c-programming/145187-how-pick-random-number-between-x-y.html

PARTNERS