Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unique Random Numbers

    This script picks a number of unique random numbers from an array.
    Demo : http://www.qiksearch.com/javascripts...m_numbers1.htm

    Code:
    <script language="JavaScript">
    // Unique Random Numbers Picker
    // By Premshree Pillai
    
    var numArr = new Array("0","1","2","3","4","5","6","7","8","9"); // Add elements here
    var pickArr = new Array(); // The array that will be formed
    var count=0;
    var doFlag=false;
    var iterations=0;
    
    function pickNums(nums)
    {
     iterations+=1;
     var currNum = Math.round((numArr.length-1)*Math.random());
     if(count!=0)
     {
      for(var i=0; i<pickArr.length; i++)
      {
       if(numArr[currNum]==pickArr[i])
       {
        doFlag=true;
        break;
       }
      }
     }
     if(!doFlag)
     {
      pickArr[count]=numArr[currNum];
      document.write('<b>' + numArr[currNum] + '</b> <font color="#808080">|</font> ');
      count+=1;
     }
     if(iterations<(numArr.length*3)) // Compare for max iterations you want
     {
      if((count<nums))
      {
       pickNums(nums);
      }
     }
     else
     {
      location.reload();
     }
    }
    
    pickNums(5); // Call the function, the argument is the number of elements you want to pick.
                 // Here we pick 5 unique random numbers
    </script>

  • #2
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can the above script be used for midi or graphics? If so, what are the modifications? Thanks!

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, you can use the script for midi/graphics. You will have to make modifications, in the ouput format.

    See this link :
    http://www.ourindooroopilly.com/lottopicker.html



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •