Old 20th May 2002, 21:48   #1
DJGrenola
Registered User
 
DJGrenola's Avatar
 
Join Date: May 2002
Location: Can't remember
Posts: 268
MAKI: random number generator: bug

Just a quickie to say that the random number generator in MAKI (build #466) currently won't produce integers greater than about 30000 (I'm assuming the limit is 32768.)

To prove this, try the following code snippet:

code:


Int successes1 = 0;
Int successes2 = 0;
Int i;

for (i=0;i<1000000;i++) {
Int r = random(100000);
if (r > 33000)
successes1++;
if (r > 32000)
successes2++;
}

messageBox ("times greater than 33000: " + integerToString(successes1) + ", times greater than 32000: " + integerToString(successes2), "random number test", 0, "");




(Be warned, it takes quite a while to run. You can reduce the loop size in the for statement if you feel like it.)

You will end up with the program counting tens of thousands of random number occurrences greater than 32000, but none at all greater than 33000.

DJG
DJGrenola is offline   Reply With Quote
Old 20th May 2002, 22:16   #2
DJGrenola
Registered User
 
DJGrenola's Avatar
 
Join Date: May 2002
Location: Can't remember
Posts: 268
workaround

Sorry, I forgot to mention that you can always create larger random numbers this way:

code:


#define RANDOM_MAX 10000

Int big_random = stringToInteger(integerToString(random(RANDOM_MAX)) + integerToString(random(RANDOM_MAX)));




which should give you a random number between 1 and 99999999.
DJGrenola is offline   Reply With Quote
Old 21st May 2002, 05:50   #3
Naamloos
Forum King
 
Naamloos's Avatar
 
Join Date: Mar 2001
Location: irc.tehflap.org/*******
Posts: 3,085
buglist?
Naamloos is offline   Reply With Quote
Old 21st May 2002, 06:06   #4
simon snowflake
Skin Wizard
(Forum King)
 
simon snowflake's Avatar
 
Join Date: Aug 2000
Location: Gent, Belgium. does anybody know where the toilets are?
Posts: 4,636
Send a message via ICQ to simon snowflake
sorry, but what can you do with this?

don't be a thief of your own life.... : DEXYD - Digitally EXpressing Your Dreams

Join the Winamp Enthusiasts Forum - Join the Winamp Skin Love facebook group:
simon snowflake is offline   Reply With Quote
Old 21st May 2002, 15:14   #5
DJGrenola
Registered User
 
DJGrenola's Avatar
 
Join Date: May 2002
Location: Can't remember
Posts: 268
Sorry, you've lost me. What can you do with what ? The random number generator ?

Also, here's a generalised workaround which will produce a random number of any size up to the value of the Int data type (range from 0 to the specified limit, inclusive).

code:


Int largeRandom (Int limit) {

if (limit < 0) {
messageBox ("in largeRandom(): negative limit specified", "ERROR", 0, "");
return -1;
}

Int quotient = limit / 10000;
Int remainder = limit % 10000;
Int i;
Int current = 0;
for (i=0;i<quotient;i++)
current = current + random (10001);
if (remainder > 0)
current = current + random (remainder + 1);
return current;

}




DJG
DJGrenola is offline   Reply With Quote
Old 21st May 2002, 15:23   #6
Plague
f(caffeine){
return wasabi;
}
(Forum King)
 
Plague's Avatar
 
Join Date: Jul 2001
Location: Sweden
Posts: 3,984
what can you do with a random number generator?
well, there are several things...
things like:
black jack ala winamp3
winamp3 roulette

and so on...

-Plague
Plague is offline   Reply With Quote
Old 21st May 2002, 15:29   #7
DJGrenola
Registered User
 
DJGrenola's Avatar
 
Join Date: May 2002
Location: Can't remember
Posts: 268
Well, I'm using it to make the lights on my skin flicker randomly from time to time, but yeah, that too ... =)

DJG
DJGrenola is offline   Reply With Quote
Old 3rd July 2002, 23:55   #8
spleen
Senior Member
 
spleen's Avatar
 
Join Date: Feb 2002
Location: Split, Croatia
Posts: 180
Send a message via ICQ to spleen
Has anyone tested why this doesn't work?
code:
Int largeRandom (int Limit) {
if (Limit>32767) Limit=32767;
int Random1 = System.random(Limit);
int Random2 = System.random(Limit);
int Random3 = System.random(Limit);
int Random4 = System.random(Limit);
int BigRandom = Random1 * Random2 * Random3 * Random4;
return BigRandom;
}


Cause (2^8)*(2^8)*(2^8)*(2^8)=2^32. That fits in int size.
spleen is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Skinning and Design > Modern Skins

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump