GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Feb-2007, 10:00
markyp markyp is offline
New Member
 
Join Date: Nov 2006
Posts: 26
markyp is on a distinguished road
Lightbulb

Randomisation


hi am doing my code now for a multipul choice testing system and am unsure how I can randomise the code in order for the questions to come out in various orders? Anone have any comments or suggestions
  #2  
Old 28-Feb-2007, 20:59
Blake's Avatar
Blake Blake is offline
Member
 
Join Date: Nov 2005
Posts: 172
Blake will become famous soon enough

Re: Randomisation


Write a function that will randomly swap two questions, and call it about 100 times.
__________________
www.blake-foster.com
  #3  
Old 05-Mar-2007, 07:34
markyp markyp is offline
New Member
 
Join Date: Nov 2006
Posts: 26
markyp is on a distinguished road

Re: Randomisation


i have 40 questions would i need to but these in a loop liek a do while loop?
  #4  
Old 05-Mar-2007, 11:04
Blake's Avatar
Blake Blake is offline
Member
 
Join Date: Nov 2005
Posts: 172
Blake will become famous soon enough

Re: Randomisation


Something like this:

PHP Code:

<html>
<head>
<title>random shuffle</title>
</head>
<body>

<?php

$numQuestions = 10;

$questions = Array(numQuestions);

$questions[0] = "Question 0";
$questions[1] = "Question 1";
$questions[2] = "Question 2";
$questions[3] = "Question 3";
$questions[4] = "Question 4";
$questions[5] = "Question 5";
$questions[6] = "Question 6";
$questions[7] = "Question 7";
$questions[8] = "Question 8";
$questions[9] = "Question 9";

srand(time());

for ($i=0; $i<100; $i++)
{
    $rand1 = rand()%$numQuestions;
    $rand2 = rand()%$numQuestions;

    $temp = $questions[$rand1];
    $questions[$rand1] = $questions[$rand2];
    $questions[$rand2] = $temp;
}

for ($i=0; $i<$numQuestions; $i++)
{
    echo $i . ".<br>" . $questions[$i] . "<br><br>";
}

?>

</body>
</html> 


Here it is working:

http://www.blake-foster.com/demo/shuffle.php
__________________
www.blake-foster.com
  #5  
Old 05-Mar-2007, 12:47
markyp markyp is offline
New Member
 
Join Date: Nov 2006
Posts: 26
markyp is on a distinguished road
Thumbs up

Re: Randomisation


Quality, thanks a lot for the help looks class

much appreciated
 
 

Recent GIDBlog2nd Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Order randomisation of content with PHP I, Brian MySQL / PHP Forum 1 18-Sep-2005 17:46

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 03:21.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.