well you cant put all this inside one function just like that

You have to watch on scope. Paste all this code beside other functions not inside. And then just use GetUniform()+0.5|0; to get random number inside your function or wherever you need it.

I must go now, hope I helped you

cya

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?

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

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

nooooooooooooooooooooooooooooooooooooooooooooooooooooCalls to Math are expensive since this will be every frame use bitwise tricks

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

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

Lance, if you looking to develop a multiplayer game, you could finsih off Envato World I think it has potential to be really cool

You’re “Envato World” is not updated, I’ve changed my logo and name

(my previous name was IGIsoftware)

Hello Mr. Robert Elias, remember me? My name here used to be igisoftware…yes, now you remember…

Authors be careful with this guy, he is **cheater**. I used to work for him on small project, he needed job done in 3 hours! Since I’ve never had bad experiences with buyers here and it was small project, I didn’t take his money upfront. I accepted offer and finished project within 3 hours, he was satisfied, but then when it was his turn to pay me, he started making up excuses … and guess what, after some time he stopped answering my email and he never payed me.

here is thread where he posted request for that project:

http://activeden.net/forums/thread/need-a-form-for-flash-/13774?page=1

This iPad brings only disappointment…

There shouldn’t be a problem with design, it’s ok. This is 404 popup jquery script, it’s not template that must have some sick design. I think reviewer owns you a better explanation…

So… repeated in a corrected way;y1 and y2 are 2D-vectors, given by

y1 = a1.cos(wt-p1)

y2 = a2.cos(wt-p2)

where a1 and a2 are the lengths of the vectors and wt,p1 and p2 are angles (with respect to some axis).

Show that the squared-length I = |y1+y2|^{2 of the sum of the two vectors is given by I = a12 + a22 +2.a1.a2.cos(p2-p1)}For the solution

I = |y1+y2|2 = |y1|

where |y| means the absolute value/length of vector y and y1*y2 means inner product between vectors y1 and y2^{2 + |y2|}2 + 2.y1 times y2

= |y1|^{2 + |y2|}2 + 2.|y1||y2|.cos( angle between y1 and y2 )

= a12 + a22 + 2.a1.a2.cos( (wt-p1)-(wt-p2) )

= a12 + a22 + 2.a1.a2.cos( p2-p1 )

Your solution is partially correct, but explanation is not so good

y1(t) and y2(t) are not vectors they are functions and you can’t apply this formula on functions only on vectors.

He said this is physics problem, so they probably talk about waves, signals or something similar represented with wave function y(t) = A.cos(wt – p)

where A is amplitude, w is frequency, and p is phase.

so y1 and y2 are not vectors, they are cosine waves, where a1 and a2 are amplitude of each wave, w is frequency, t is current time and p1 and p2 are phases(how much each wave lates in time).

This two cosine waves have same frequency, so their sum will be also wave with same frequency but different phase and different amplitude.

I(t) = y1(t) + y2(t) = Iamplitude * cos(wt – p3)

Solution:

let’s stop time at the moment where t=0 we will have:

wt=0;

y1(t) = a1.cos(-p1)

y2(t)=a2.cos(-p2)

now we can draw vectors in phasor diagram

so there are 3 vectors with different lengths. Now we can use cosine law or the method that patrickjansen wrote, to calculate length of Iamplitude.

if we move begining of the a1 vector at the and of a2 we will get triangle with sides a1, a2 and Iamplitude. We can use cosine law to calculate length of Iamplitude.

so we have now:

Iamplitude ^ 2 = a1 ^ 2 + a2 ^ 2 – 2.a1.a2.cos(180-p2+p1)

where 180-p2-p1 is angle between a1 and a2 in formed triangle.

knowing that cos(180-x)=-cos(x)

Iamplitude ^ 2 = a1 ^ 2 + a2 ^ 2 + 2.a1.a2.cos(p2-p1)

and that’s it