My favorites | Sign in
Project Home Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 163: Bad random number generator
1 person starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Apr 2012


 
Reported by jonasmal...@gmail.com, Mar 24, 2012
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
cpp.PNG
341 KB   View   Download
neko.PNG
348 KB   View   Download
Mar 24, 2012
#1 jonasmal...@gmail.com
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 ) );
      }
Mar 31, 2012
Project Member #2 gameh...@gmail.com
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
Project Member #3 gameh...@gmail.com
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
Project Member #4 gameh...@gmail.com
Actually, you have a good point - I have fixed this.
Status: Fixed

Powered by Google Project Hosting