/ Published in: ActionScript 3
URL: http://www.flashfiles.nl/ShowDetail.asp?NewsId=6080
I always seem to forget about the Math class and its functions and possibilities… So I created this snippet as an easy reminder. Feel free to send me suggestions or extras I might add!
Expand |
Embed | Plain Text
n = Math.random(); // 0 <= n < 1 n = Math.round(x); // rounds x to the closest integer n = Math.floor(x); // rounds x downwards to the closest integer n = Math.ceil(x); // rounds x upwards to the closest integer n = Math.round(Math.random()*10); // 0 <= n <= 10 n = Math.ceil(Math.random()*10); // 1 <= n <= 10 n = Math.floor(Math.random()*10); // 0 <= n <= 9 n = Math.random()*10 + 5; // 5 <= n <= 15 n = Math.round(Math.random())*2 - 1; // n will randomly be -1 or 1
You need to login to post a comment.
