Page 10 of 10

Re: FW: bad rand generator: distribution/prevalences/periodicity

Posted: 07 Jul 2011, 10:13
by HaWe
it IS already available!
look at the test_release section, it's from July 3rd, 2011

Re: FW: bad rand generator: distribution/prevalences/periodicity

Posted: 07 Jul 2011, 20:35
by spillerrec
I don't quite understand the test code, why should it run for 5 minutes? Something like this:

Code: Select all

task main(){
	DrawCircleType circle;
	
	repeat( 100 ){
		circle.Center.X = Random( 100 );
		circle.Center.Y = Random( 64 );
		circle.Size = 3;
		SysDrawCircle( circle );
		circle.Size = 5;
		SysDrawCircle( circle );
		circle.Size = 7;
		SysDrawCircle( circle );
	}
	
	Wait( 10000 );
}
finishes in less than a second... (I have not updated yet, therefore Random().)

Re: FW: bad rand generator: distribution/prevalences/periodicity

Posted: 08 Jul 2011, 20:30
by afanofosc
I don't think the program was designed to be a test of the RNG so much as it was just a program that used random numbers - probably as part of a game, I imagine, and it happened to show a less than ideal randomness to the targets displayed on the LCD. I don't think Doc or the original code's author intended to suggest that delaying between calls to the RNG had any bearing on the quality of the numbers it produced.

In any case, I would encourage users of NXC to use the latest enhanced NBC/NXC firmware and the new rand() and srand() functions. If you must continue to use the standard firmware then use Random(n) to generate "good enough" random numbers between 0 and N or use rand() but not with % N as the means for obtaining a random number between 0 and N. Please, do not use Doc's Mersenne Twister implementation to get a random number unless you are running some kind of simulation on your NXT that requires an extremely high quality random number generator.

John Hansen