I am trying to create many objects with a different z value.
The z variable should have a value between 0 and 1.
I am using the following
[AS]
1 - Math.round(Math.random() * 4) * 0.2;
[/AS]
This should randomly give one of the following answers
1, 0.8, 0.6, 0.4 or 0.2
However, that isn’t the case, sometimes it would give something like 0.3999999999999999
which is close but I need it exact.
So I ran the following simple test
[AS]
for (var i:uint = 0; i < 5; ++i) {
trace(i * 0.2);
}
trace(’-----’);
for (i = 0; i < 5; ++i) {
trace(1 - i * 0.2);
}
[/AS]
And I received the following results
0
0.2
0.4
0.6000000000000001
0.8
1
0.8
0.6
0.3999999999999999
0.19999999999999996
If someone could tell me where I am going wrong or how I can fix this, that would be fantastic.
Thank you
Dhryn