By 05/02/2014 5 Comments

How to generating a random number between 1 to n

Generate Random numbers

  • We can generate random numbers in javascript
  • These random numbers are automatically generated by javascript
  • These random numbers are used for game programs, data encryption etc

random()

  • This function is used to generate random numbers
  • This function belongs with math object and can be called as Math.random()
  • This function generate a random or unique number each time

The following code describes the example about random numbers

<script>

//random number from 1 to N
var random = Math.floor(Math.random() * N + 1);

//random number between 1 and 10
var random = Math.floor(Math.random() * 10 + 1);

//random number between 1 and 100
var random = Math.floor(Math.random() * 100 + 1);

</script>






Posted in: JavaScript

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .