How to create a function to get a random number.

## Math.random

We will use the Math.random function.

## Example

**Math.random()*3** will return **0**, **1** and **2**.

1 2 3 4 5 6 7 8 9 10 11 |
var players = Array(); players[0] = "Max"; players[1] = "Ted"; players[2] = "Marshall"; var randomnumber=Math.floor(Math.random()*3) alert(players[randomnumber] + "!"); |