I want to use javascript to generate 50 no-repeat random numbers and the number is in the range 1 to 50.how can I realize it?The 50 numbers stored in a array.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First generate an ordered list:
then shuffle it.
I tested the above method and it performed well. However, the ECMAScript spec does not require
Array.sortto be implemented in such a way that this method produces a truly randomized list – so while it might work now, the results could potentially change without warning. Below is an implementation of the Fisher-Yates shuffle, which is not only guaranteed to produce a reasonably random distribution, but is faster than a hijacked sort.