FW: bad rand generator: distribution/prevalences/periodicity

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post by HaWe »

it IS already available!
look at the test_release section, it's from July 3rd, 2011
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

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

Post 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().)
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

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

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 1 guest