| Issue 163: | Bad random number generator | |
| 1 person starred this issue and may be notified of changes. | Back to list |
I haven't looked into the issue yet, but the random number generator for the hxcpp target seems to have some problems...
On a test app that renders random elipses with random colors according to
{{{
colors.set( key, Std.random( 0x1000000 ) );
shapes.set( key, Elipse( 1. + Math.random() * 10, 1. + Math.random() * 10 ) );
}}}
I get a very "bad" distribution in cpp. Please check the attached pictures...
haxe 2.08
hxcpp 2.08.3
windows 7 x64
Mar 31, 2012
hmm looks like it is only getting the bottom 16 bits, and chopping off the red bits. I will have a look.
Apr 5, 2012
Hi, The integer version uses the standard c++ "rand" function, and modulo operator. This is ok for small numbers, but you need to use Std.int(Math.random( ) ) for larger values. If your max-number were not a power of two, there would also be a slight bias for lower numbers using the integer version with a large argument, so the Float version is generally better.
Status:
WontFix
Apr 10, 2012
Actually, you have a good point - I have fixed this.
Status:
Fixed
|
I forgot to mention that there is a pattern to key: for ( i in 0...1000 ) for ( j in 0...500 ) if ( i % 10 == 0 && j % 10 == 0 ) { var key = i * 1000 + j; colors.set( key, Std.random( 0x1000000 ) ); shapes.set( key, Elipse( 1. + Math.random() * 10, 1. + Math.random() * 10 ) ); layer1.addObject( key, new Vector( i + 20, j + 20 ) ); }