unique Random Number


/ Published in: JavaScript
Save to your folder(s)

first of all i thank to our Creator and Mr.ImHugo for his Action script which i make the java script from it,its works fine and once again i gives thank him for his snippet


Copy this code and paste it in your HTML
  1. #
  2. // ************************************************** //
  3. #
  4. // Author: John Sujith Kumar
  5. #
  6. // URL: http://www.suzerain.isgreat.org
  7. #
  8. // ************************************************** //
  9. #
  10.  
  11. #
  12. // Vars
  13. function uniqueRandomNumber(inPutArray){
  14. var sArray = new Array();
  15. var storeList = new Array();
  16. // Inserts Numbers in Array
  17. for(var i= 1; i<=inPutArray; i++){
  18. sArray.push(i);
  19. }
  20. // Outputs numbers non-repeated
  21. for(var k= 1; k<=inPutArray; k++){
  22. // Search for value inside the Array in a random position
  23. var randomPos= Math.floor( Math.random() * sArray.length );
  24. // Selects value and removes it from Array
  25. var valueFromArray = sArray.splice(randomPos, 1);
  26. // Converts value in number
  27. var numberRand = parseInt(valueFromArray);
  28. //store and make array key for as like 0,1,2 for length :3
  29. storeList.push(numberRand-1);
  30. }
  31. alert(storeList);
  32. }
  33.  
  34. uniqueRandomNumber(3);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.