Isn’t there a way to Math.random()? For example with an array?
If yes… how can i do this?
Thanx
- Has been a member for 4-5 years
- Author was Featured
- Contributed a Tutorial to a Tuts+ Site
- Netherlands
- Community Moderator
- Microlancer Beta Tester
- Sold between 10 000 and 50 000 dollars
- Repeatedly Helped protect Envato Marketplaces against copyright violations
- Exclusive Author
You will have to make your question a bit more specific. There is a way to Math.random()... simply by using Math.random().. I don’t understand your question at all 
yourArray[uint(Math.random()*yourArray.length)]
Well,
In my previous post i asked if there was a an alternative for Math.random() becouse i can not use this in a google banner. you for example came up with this solution: var my_date:Date = new Date(); trace(my_date.valueOf())
But that doesn’t do the trick.
tried some other things…. also don’t work.
now some one told me i can fix the Math.random() issue by making an array that gives back 0 or 1
i just don’t know how to do this…. So i thing the thread title is wrong… It should have been how to create a random number with the use of an array 
- Author was Featured
- Sold between 50 000 and 100 000 dollars
- Author had a Free File of the Month
- Bought between 1 and 9 items
- Exclusive Author
- Europe
- Has been a member for 3-4 years
- Referred between 10 and 49 users
- Repeatedly Helped protect Envato Marketplaces against copyright violations
I dont understand why you cant use Math.random?
As a alternative you could pre populate array with random values:
var a:Array = [2,4,0,1,5];
and then pull out indexes in order.
for(var i:int=0; i < a.length; i++){
trace(i);
}
I dont understand why you cant use Math.random?As a alternative you could pre populate array with random values:
var a:Array = [2,4,0,1,5];
and then pull out indexes in order.
for(var i:int=0; i < a.length; i++){ trace(i); }
Hi,
Thanx for the reply! the reason why i cant use Math.random() is becouse google ads doesn’t allow flashbanner to have a random value. If it has the file can not be uploaded!
Ill give your solution a try! 
I dont understand why you cant use Math.random?As a alternative you could pre populate array with random values:
var a:Array = [2,4,0,1,5];
and then pull out indexes in order.
for(var i:int=0; i < a.length; i++){ trace(i); }Hi,
Thanx for the reply! the reason why i cant use Math.random() is becouse google ads doesn’t allow flashbanner to have a random value. If it has the file can not be uploaded!
Ill give your solution a try!![]()
I Don’t understand why are you not able to use the solution which was provided in http://activeden.net/forums/thread/google-banner/22211?page=1#207981
Math.random() returns number between 0 and 1
And the following:
var my_date:Date = new Date(); var myMathRand = my_date.getMilliseconds()/1000;
will return a number between 0 and .999
You have to understand that in your code, you are using Math.random() everytime you want a new random number, so you should create a new ‘myMathRand’ before your line of code where you want to use it.
Google just doesn’t allow Math.random() in the code. It’s some kind of security thing.
For me
var my_date:Date = new Date(); var myMathRand = my_date.getMilliseconds()/1000;
Doesn’t work, becouse i’m also using Math.round cuz i need a round value of 1 or 0 for my animation. If I use milliseconds for this… it will not be random enough… then i will get a couple of 0 following each other and a couple of 1 following up on each other. It’s just not random enough!
var a:Array = [0,1]
for(var i:int=0; i < a.length; i++){ trace(i); }
Should work… but also this is not random enough… i need the output of the array to be more random like : 1,1,0,1,0,0,1,0,0,0 and not 0,1,0,1,0,1,0,1
How can i do this without using Math.random of random()?
Thanx 
Google just doesn’t allow Math.random() in the code. It’s some kind of security thing.For me
var my_date:Date = new Date(); var myMathRand = my_date.getMilliseconds()/1000;
Doesn’t work, becouse i’m also using Math.round cuz i need a round value of 1 or 0 for my animation. If I use milliseconds for this… it will not be random enough… then i will get a couple of 0 following each other and a couple of 1 following up on each other. It’s just not random enough!
var a:Array = [0,1]
for(var i:int=0; i < a.length; i++){ trace(i); }
Should work… but also this is not random enough… i need the output of the array to be more random like : 1,1,0,1,0,0,1,0,0,0 and not 0,1,0,1,0,1,0,1
How can i do this without using Math.random of random()?
Thanx![]()
it is little cumbersome but you can make an array of 999 values like – myArray = [0,1,1,0,0,1,1,0,1,0,1,0,1,0,1 .. and so on ..]; use myMathRand = my_date.getMilliseconds()/1000;
instead of directly using myMathRand, use myRandomNumber = myArray[myMathRand];
Let us know.
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
