- Attended a Community Meetup
- Community Moderator
- Has been a member for 5-6 years
- United Kingdom
- Contributed a Tutorial to a Tuts+ Site
- Won a Competition
- Contributed a Blog Post
- Beta Tester
- Bought between 50 and 99 items
just use Math.round(GetUniform()); for 0 and 1
noooooooooooooooooooooooooooooooooooooooooooooooooooo 
Calls to Math are expensive
since this will be every frame use bitwise tricks 
http://gskinner.com/talks/quick/#48
nice algorithm though 
Here you go man![]()
I remember we learned this stuff on Algorithms and Data structures subject I had 2 years ago, so I found algorithm in C++ and modified it. It’s your lucky day
var date:Date = new Date(); //we use date to get different seeds //seeds var m_w:uint = date.getSeconds()+1; //must not be 0, so we add 1, that should work... var m_z:uint = date.getMilliseconds()+1; //same here.. //Marsaglia's MWC algorithm function GetUint():uint { m_z = 36969 * (m_z & 65535) + (m_z >> 16); m_w = 18000 * (m_w & 65535) + (m_w >> 16); return (m_z << 16) + m_w; } function GetUniform():Number { var u:uint = GetUint(); return (u + 1) * 2.328306435454494e-10; } //100 random numbers between 0 and 1 for(var i=0; i<100; i++){ trace(GetUniform()); }p.s.
don’t try to understand how it works, just use it
edit:
just use Math.round(GetUniform()); for 0 and 1
Ivan
Thanx alot ivan! 
But i cant seem to get it to work for as2. Keep on sying that it can’t load the right class?!
Any ideas 
noooooooooooooooooooooooooooooooooooooooooooooooooooo![]()
Calls to Math are expensive
since this will be every frame use bitwise tricks
http://gskinner.com/talks/quick/#48
nice algorithm though![]()
hehehe, you’re right, that would be much better solution 
Thanx alot ivan!![]()
But i cant seem to get it to work for as2. Keep on sying that it can’t load the right class?!
Any ideas![]()
why you use as2? There is no unsigned integer data type in as 2…that’s the problem 
why you use as2? There is no unsigned integer data type in as 2…that’s the problem![]()
Yeah, i’v taken that out… but still no difference! but i probably need uint to get it to work?!
any other ideas 
why you use as2? There is no unsigned integer data type in as 2…that’s the problem![]()
Yeah, i’v taken that out… but still no difference! but i probably need uint to get it to work?!
any other ideas![]()
The reason why i use AS2 is becouse i’ve made the script a long time ago. But now i just need to update it so i can use the banner for Google adwords

- Attended a Community Meetup
- Community Moderator
- Has been a member for 5-6 years
- United Kingdom
- Contributed a Tutorial to a Tuts+ Site
- Won a Competition
- Contributed a Blog Post
- Beta Tester
- Bought between 50 and 99 items
But i cant seem to get it to work for as2. Keep on sying that it can’t load the right class?!
what class is that, whats the error exactly? Maybe its a hint to use AS3 
But i cant seem to get it to work for as2. Keep on sying that it can’t load the right class?!what class is that, whats the error exactly? Maybe its a hint to use AS3![]()
Yeah, i know its AS3 . But i don’t have that much knowledge of AS3 to rebuild my whole application 
I’m still oldscool 
As I said, this is your lucky day 
var date:Date = new Date(); //we use date to get different seeds
//seeds
var m_w:Number = date.getSeconds()+1;
var m_z:Number = date.getMilliseconds()+1;
//Marsaglia's MWC algorithm
function GetUint():Number
{
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w;
}
function GetUniform():Number
{
var u:Number = GetUint();
return (castToUint(u) + 1) * 2.328306435454494e-10;
}
//100 random numbers
for(var i=0; i<100; i++){
trace(GetUniform()+0.5|0);
}
function castToUint(x:Number):Number{
return x < 0 ? x+4294967295 : x;
}
problem is there is no uint data type in as2, so it reports error that class or interface ‘uint’ could not be loaded. But I came to idea to “make” uint with this
return x < 0 ? x+4294967295 : x;
so if its less than 0 add maximum value of uint so you get positive representation of that value. That should do the job. 
Ivan
Thanx Ivan,
Guess it is my lucky day
Now i’m getting a returned value!
The only thing is…. the only return value that i get is 0.
Any ideas why that’s the case? 
Thanx Ivan,Guess it is my lucky day
Any ideas why that’s the case?Now i’m getting a returned value! The only thing is…. the only return value that i get is 0.
![]()
well I guess your doing something wrong, because this works fine for me. 
