8269 posts Community Moderator
  • Has referred 10+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Attended one of our Meetups around the world
+9 more
MSFX Moderator says
just use Math.round(GetUniform()); for 0 and 1

noooooooooooooooooooooooooooooooooooooooooooooooooooo :P

Calls to Math are expensive :( since this will be every frame use bitwise tricks :)

http://gskinner.com/talks/quick/#48

nice algorithm though :)

68 posts
  • Has been part of the Envato Community for over 7 years
  • Has sold $1,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
botervet says
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 :D


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 :)

199 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
ivank says
noooooooooooooooooooooooooooooooooooooooooooooooooooo :P

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 :)

68 posts
  • Has been part of the Envato Community for over 7 years
  • Has sold $1,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
botervet says
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 :)

68 posts
  • Has been part of the Envato Community for over 7 years
  • Has sold $1,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
botervet says
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

:)

8269 posts Community Moderator
  • Has referred 10+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Attended one of our Meetups around the world
+9 more
MSFX Moderator says
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 :)

68 posts
  • Has been part of the Envato Community for over 7 years
  • Has sold $1,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
botervet says
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 :)

199 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
ivank says

As I said, this is your lucky day :D


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

68 posts
  • Has been part of the Envato Community for over 7 years
  • Has sold $1,000+ on Envato Market
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
botervet says

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? :)

199 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+2 more
ivank says
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? :)

well I guess your doing something wrong, because this works fine for me. :D

by
by
by
by
by
by