Re: Diferent numbers



In news:d9gp2c$j75$1@xxxxxxxxxxxxxx,
CyberDog <milan-SPAM-@xxxxxxxxxxxx> wrote:
> Andrew @ Rockface wrote:
>> As each number is generated record it in an array, then check each
>> new number against the elements in the array.
>
> I would like to go with this
>
> Could you be so kind and write an example for me?
>
> is it something like this:
>
> while ($postition < $displayed_questions)
> {
> $question = array(
> $number => rand(1, $questions_in_database)
> )
> $number++
> }
>
> How to check if the number is used? While in a while?

I think the shuffle is the best way, unless you've got a massive amount of
questions :)

$questions_in_database = 10;
$questions = range(0,$questions_in_database);
shuffle($questions);
for ($c = 0; $c < 5; $c++) {
echo "RANDOM NUMBER =".$questions[$c]."<br>";
}

If you want to use the other method:

$questions_in_database = 5;
$questions = array();
for ($c = 0; $c < 5; $c++) {
$rnd = mt_rand(0,$questions_in_database);
if (! in_array($rnd, $questions)) {
$questions[] = $rnd;
}
}
echo "<pre>";print_r($questions);echo "</pre>";

--
Andrew @ Rockface
np: 1000 Suns - 5 [stopped]
www.rockface-records.co.uk


.



Relevant Pages

  • Re: From ushot to byte[]
    ... Andrew ... > I've a ushort variable and I need to copy it in an array of byte. ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Keeping an Array in Memory
    ... Andrew wrote: ... > reloaded each time a .php script is run. ... I could load the array from a file ... > stay in memory until the server is shutdown ...
    (comp.lang.php)
  • Re: question about max_readahead for ide devices in 2.4?
    ... Andrew> That's correct - it's all a bit weird. ... sets an entry in the read_aheadarray. ... Or am I missing something else?? ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: 2 dimension arrays
    ... How do I declare an array as a session variable? ... "Hans Kesting" wrote: ... >> Andrew. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: 2 dimension arrays
    ... Andrew wrote: ... > and editing the array. ... This is unique to each user in the session. ... If you want to retain user-specific data in server-memory, ...
    (microsoft.public.dotnet.framework.aspnet)