03 January 2012, 15:38 | #1 |
Junior Member
Join Date: May 2002
Location: Manchester
Age: 54
Posts: 61
|
Picking names at random from a list
Hi there, i have decide to learn Basic programming, and i have done the little things in AMOS.
the problem i have is i have 12 names that i want to be picked at random and then print to screen i.e name 5 name 1 name 12 name 10 and so on how do i do this please |
03 January 2012, 19:07 | #2 | |
Registered User
Join Date: Sep 2007
Location: Las Cruces, USA
Age: 71
Posts: 351
|
Quote:
Stores the 12 names into a string array, use a random generator to pick which one, mark that one with an integer array as being used, run the random generator until you get a name that hasn't been used. If AMOS doesn't have a random generator then there are several ways to make simple ones with floating pointer numbers. Somewhere I have a simple one but I can't find it, it does from 0 to 1.0 so you scale and offset it to get what you want. |
|
03 January 2012, 19:59 | #3 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
In AMOS you can use f.ex Rnd(10) to return an integer from 0 up to and including 10, and if you insert the line Randomize Timer in the beginning then you get different numbers every time you run your program.
|
03 January 2012, 20:16 | #4 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
What you need is a shuffling algorithm. Durstenfelds shuffling algorithm is the best one, as it can only pick each item in your list once, and it has no bias (meaning that any bias comes from your random number generator, and from not implementing some extra code to handle a certain kind of bias).
If you have questions, ask Fisher-Yates shuffle: http://en.wikipedia.org/wiki/Fisher–Yates_shuffle Durstenfeld shuffle for computer use: http://en.wikipedia.org/wiki/Fisher–...dern_algorithm |
04 January 2012, 17:29 | #5 | |
Registered User
Join Date: Sep 2007
Location: Las Cruces, USA
Age: 71
Posts: 351
|
Quote:
Doesn't a shuffle algorithm still have to have some kind of random generator in it? The shuffle still has to be random and therefor can still have a bias. |
|
04 January 2012, 18:14 | #6 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Quote:
Another shuffling algorithm (a very bad one) picks two random numbers and swaps the entries in the list you're shuffling based on those two picks. This is a biased method. Even when your RNG is completely bias free, this shuffling algorithm's output will still be biased. |
|
04 January 2012, 22:43 | #7 |
Registered User
Join Date: Jan 2011
Location: -
Posts: 728
|
It feels so weird going back to BASIC after so many years of using proper languages C, C++, etc., but I decided to give it a try. Booted up AMOS and came up with the following:
(sorry. No idea how to export as text in AMOS, so a screenshot it is) It creates an array of 10 entries (well, 11 according to the manual, which is why there's index 10), selects a random number, then displays that entry. Super simple. A shuffle algorithm is overkill for such a simple task Hope that helps you, Champions_2002. |
05 January 2012, 05:33 | #8 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
|
05 January 2012, 21:05 | #9 | |
Registered User
Join Date: Sep 2007
Location: Las Cruces, USA
Age: 71
Posts: 351
|
Quote:
|
|
05 January 2012, 23:22 | #10 | |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
|
Quote:
I just listed Durstenfelds algorithm because it's the most efficient. It allows you to shuffle any kind of array in-place, and it only has to re-pick a random number once in a while (although for big moduli this will take extra code to handle efficiently). Also, for smaller arrays, it's possible to use a modulus list, making the thing even faster. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Random question | 251Mario | project.EAB | 1 | 16 May 2013 02:19 |
Picking up the PCMCIA compact flash adapter in WB3.1 | pubzombie | New to Emulation or Amiga scene | 10 | 18 March 2011 15:07 |
Executioner - picking up stuff | Crowley | support.Games | 0 | 08 June 2010 04:12 |
List in alphabetical order in dropdown list of Floppy Drives | Zed | request.UAE Wishlist | 1 | 06 February 2010 17:26 |
Amiga Demoscene Archive: picking up speed... | Paul | News | 0 | 21 February 2005 11:40 |
|
|