Jump to content

Random Help


shage

Recommended Posts

Im trying to figure out how to click say random 16 check boxes of say 48 in a form, its for a role playing game that has questions that you can either fill out or in most lazy peoples case just random answer to get your class, but i cant seem to figure out how to pick 16 answers on random on one form thank you

Link to comment
https://forums.phpfreaks.com/topic/154397-random-help/
Share on other sites

maybe something like this (may have a few bugs, As I didn't test it):

 

var myArray = new Array();
function in_array(val){
     for(var i=0;i<myArray.length;i++){
          if(myArray[i] == val) return true;
     }
     return false;
}
function randomCheck(){
     var i = 0;
     while(myArray.length < 48){
          var ran = round(Math.random()*48);
          if(!in_array(ran)) {
               myArray[i] = ran;
               i++;
          }
     }
}

Link to comment
https://forums.phpfreaks.com/topic/154397-random-help/#findComment-811906
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.