why not shuffle() ?
*********** REPLY SEPARATOR ***********
On 25/03/2002 at 11.13 Svensson, B.A.T. (HKG) wrote:
>Of course the algorithm works...
>
>>-----Original Message-----
>>From: Nicole Amashta
>>Sent: Friday, March 22, 2002 4:36 PM
>>To: [EMAIL PROTECTED]
>>Subject: Re: [PHP-WIN] random elements of an array
>>
>
>[...]
>
>>I have tested this. It works, Even after you refresh the page. Try it!
>>
>>Nicole
>>www.aeontrek.com
>>
>>
>>
>>"B.A.T. Svensson" wrote in message
>>> You can completely randomize an array with n elements in n
>>operations, by
>>> using the following brute force approach:
>>>
>>> void ScrambleIntList(int *pnElements, int nLen)
>>> {
>>> for (nLoop = 0, nLoop<nLen; nLopp++) {
>>>
>>> // Pic a random element
>>> int nRandomPic = nLen * rand();
>>>
>>> //Swap current element with the random pic
>>> int nTemp = pnElement[nLoop];
>>> pnElement[nLoop] = Element[nRandomPic];
>>> pnElement[nRandomPic] = nTemp;
>>>
>>> }
>>> }
>>>
>>> /Anders
>>>
>>> >-----Original Message-----
>>> >From: Afan Pasalic [mailto:[EMAIL PROTECTED]]
>>> >Sent: Thursday, March 21, 2002 9:17 PM
>>> >To: [EMAIL PROTECTED]
>>> >Subject: [PHP-WIN] random elements of an array
>>> >
>>> >
>>> >Hi,
>>> >
>>> >My problem is: if I have an array (e.g. 1, 2, 3, 4, 5, 6, 7,
>>> >8, 9), how I can "shake" the array and get randomized order of
>>> >the same array (e.g. 5, 8, 1, 9, 3, 4, 7, 2, 6)?
>>> >
>>> >Thanks for any help!
>>> >
>>> >
>>> >Afan
>>> >
>>
>>
>>
>>--
>>PHP Windows Mailing List (http://www.php.net/)
>>To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
>--
>PHP Windows Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
dr. Nicola Delbono
[EMAIL PROTECTED]
Key5 di Delbono Nicola
V. G.M. Rossi, 12
25038 Rovato (Bs)
Tel 39 030 7242266
Fax 39 030 7242266
www.smscitta.com | www.musicalbox.it
www.filosofo.it | www.bollicine.com
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php