We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 11/12/07


Tagged

number random function


Versions (?)


Who likes this?

3 people have marked this snippet as a favorite

vali29
blackabee
jamesming


Random Number


Published in: JavaScript 


Very simple random number generator, generates a number that then runs a function that is inside an array. Used a version of this with UFO flash script to pull in a random flash object on a page.

  1. function runMe(){
  2. var test1 = function(){
  3. alert("Test 1 has been fired");
  4. }
  5. var test2 = function(){
  6. alert("Test 2 has been fired");
  7. }
  8. var myArray = [test1, test2]
  9. var randomNumber = Math.floor(Math.random()*2);
  10. myArray[randomNumber]();
  11. }

Report this snippet 

You need to login to post a comment.