4

Possible Duplicates:
Random number generator without dupes in Javascript?
Generate 8 unique random numbers between 1 and 100

HI, I want to create an array of random numbers which should have unique values.i want to do this using java script ,Can any one give me a solution...?

Community
  • 1
  • 1
ashu
  • 1,339
  • 7
  • 27
  • 43
  • Random numbers might result in repeats... just sayin' – ajwood Dec 07 '10 at 04:15
  • If the numbers themselves need not be random consider a simple [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle). However, the question this is "getting closed" for follows this line of thinking -- which is *different* than getting a list of unique random numbers. –  Dec 07 '10 at 04:28

1 Answers1

5

Create an array of numbers:

var min = 0,
    max = 1000,
    i,
    arr = [];

for (i = min; i<max; i++)
{
    arr.push(i);
}

Then shuffle it.

Community
  • 1
  • 1
Matt Ball
  • 354,903
  • 100
  • 647
  • 710