Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Shuffling a list

Author
Message
Duke
21
Years of Service
User Offline
Joined: 24th Sep 2002
Location: United Kingdom
Posted: 9th Oct 2002 18:48
Hi

Can anyone suggest a piece of code that I could use to shuffle a list of 4 items so that I get a more or less equally random occurrence of each item?
Marc Fleury
21
Years of Service
User Offline
Joined: 1st Oct 2002
Location:
Posted: 9th Oct 2002 19:39
Assuming that your list is in an array, what you do is step through the array, and swap every value with a randomly chosen other value.



Duke
21
Years of Service
User Offline
Joined: 24th Sep 2002
Location: United Kingdom
Posted: 9th Oct 2002 22:44
Thanks Marc

Your advice is greatly appreciated. Thanks for the code snippet. I am impressed!
Marc Fleury
21
Years of Service
User Offline
Joined: 1st Oct 2002
Location:
Posted: 9th Oct 2002 23:29
There's lots more stuff like that (including a more in depth look as shuffling) on my website, under tutorials.

[url]www.dbheaven.com/tutorials.php[/url]

Login to post a reply

Server time is: 2024-03-28 08:47:11
Your offset time is: 2024-03-28 08:47:11