help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rand implementation question


From: Michael Pender
Subject: Re: Rand implementation question
Date: Fri, 28 Feb 2014 15:00:19 -0500

I understand why it is a bad idea to take successive bits from a PRNG and assume statistical independence, after all successive bits have a linear relationship to each other.  

However, profiling the use of the randi() function for comparison to rand() shows that randi() takes over ten times as long to generate random integers in my program.  An order of magnitude performance hit is a very significant compromise.

  #          Function Attr Time (s)     Calls

--------------------------------------------------------

 21             randi        173.318   2179755

  6              rand         16.941   2741950





On Fri, Feb 28, 2014 at 1:39 PM, Przemek Klosowski <address@hidden> wrote:
On 02/27/2014 10:04 PM, mpender wrote:
should be some efficient way to extract multiple bits from a single
double-precision floating point value returned by the Mersenne twister.
in general, it's a bad idea to extract bitfields from a pseudo-random number generators (it's also  famously bad to aggregate consecutive values, as shown by classic Marsaglia paper http://www.pnas.org/content/61/1/25.full.pdf)

Now, the Mersenne twister may not be subject to those problems, but one should refrain from using the generators in a way that they weren't designed or tested for. Hence, it's best to use randi() which just plain gives integers without any gymnastics.

_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave



reply via email to

[Prev in Thread] Current Thread [Next in Thread]