Page 1 of 1

selecting random values

Posted: Sat May 15, 2004 9:59 am
by justphp786
Dear all:

I have a application where I have to show 50 odd questions from the table one at a time. The question each time should be randomly selected and previously selected questions should not be reselected. I am able to generate random number with srand and rand functions.

How do I store questions previously selected?

Please giude.

Justphp786

Posted: Sat May 15, 2004 10:55 am
by markl999
Some questions ;)
1. Is this per person or 'global'? ie If i get one set of 50 questions, then my set must change next time, or if i get one set of 50 questions then everybody else must also get a different set when they load the page?
2. If it's per person, how does you app identify a person? ie is there a login system, using session, using cookies etc.. (just so we can use an existing storage method to store the questions already seen, if one exists).
3. What happens when i've seen every question is the database? Does it start again from scratch with a new random set of questions?

Posted: Sat May 15, 2004 2:21 pm
by justphp786
Answers to best of my capacity!

I have table with 200 questions and every time an user demands a question a select statement will fetch any random question from the table.

so the select statement may look like this

srand((double)microtime()*100000);
$num=rand(1,50);
select * from mytable where qnum=$num;
now if the $num is already used then it should again create another random number so that same question will not be selected.
How do we store these $num values? can we store array as cookie.