shage Posted April 16, 2009 Share Posted April 16, 2009 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 More sharing options...
jackpf Posted April 16, 2009 Share Posted April 16, 2009 You could do something that loops through each checkbox and gives it a 50% chance of being checked or not, and just repeat that until you've got 16 checked boxes. Link to comment https://forums.phpfreaks.com/topic/154397-random-help/#findComment-811855 Share on other sites More sharing options...
The Little Guy Posted April 16, 2009 Share Posted April 16, 2009 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 More sharing options...
shage Posted April 18, 2009 Author Share Posted April 18, 2009 thank you will try Link to comment https://forums.phpfreaks.com/topic/154397-random-help/#findComment-812840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.