Alice Community how do i make a random number not appear twice
 User Name Remember Me? Password

 Thread Tools Display Modes
 how do i make a random number not appear twice
 nickster654 Senior Member   Status: Offline Posts: 180 Join Date: Feb 2011 Location: nickster12345678@gmail.com how do i make a random number not appear twice - 08-16-2011, 09:07 PM i have a method where a variable makes a random number between 1 and 22 (i used the random fuction) and every time someone answers a question correct a random number is made (the numbers are connected to questions so that when a random number is chosen a random question is chosen) but sometimes (rarely) the random number will be the same as the number before, how to i make it so that a random number wont repeat?
 legolizard Senior Member     Status: Offline Posts: 242 Join Date: Jan 2011 Location: Aboard the Hyperion escaping the zerg. 08-16-2011, 09:45 PM Interesting question with a mathmatically simple explanation and a not so good way of stopping it. You see computers actually generate not-so-random numbers. This meaning the numbers generated are random to a certain extent. This is why they are called pseudo-random generators. Now there is really no concreate way to fix this as most random things aren't. The only way that might help is to make an if statment to check to see if the number is equal to a previous number and if it is then make another number. However it is still possible that you will get the same number. Does that make sense? "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein
 kidum2011 Junior Member   Status: Offline Posts: 2 Join Date: Aug 2011 Location: Israel 08-17-2011, 06:51 AM you can create an array for the whole numbers, and to set empty each number that was taken.
nickster654
Senior Member

Status: Offline
Posts: 180
Join Date: Feb 2011
Location: nickster12345678@gmail.com
08-17-2011, 10:20 PM

Quote:
 Originally Posted by legolizard Interesting question with a mathmatically simple explanation and a not so good way of stopping it. You see computers actually generate not-so-random numbers. This meaning the numbers generated are random to a certain extent. This is why they are called pseudo-random generators. Now there is really no concreate way to fix this as most random things aren't. The only way that might help is to make an if statment to check to see if the number is equal to a previous number and if it is then make another number. However it is still possible that you will get the same number. Does that make sense?
yeaa that makes perfect sense, but it would no take foreverrrr in m situation

 solution to the solution
Member

Status: Offline
Posts: 19
Join Date: Aug 2011
solution to the solution - 08-19-2011, 07:41 PM

Quote:
 Originally Posted by nickster654 yeaa that makes perfect sense, but it would no take foreverrrr in m situation
if you take his solution and add in 24 variables that change when there question is used and when the ranomizer picks the activated variable it will redo the roll until it gets a non picked number. the 24th variable activates when the original 23 are used up and will stop the randomizing loops that would cause an error. Hope this helps.

 InsertName Senior Member     Status: Offline Posts: 341 Join Date: Jun 2011 Location: In a house 08-19-2011, 08:52 PM make 2 variables (a, b). set a to random number set a to b do whatever with the variable you want set a to random number if a is equal to b repeat if not continue __№_₤⅞__ Handguns: http://www.alice.org/community/showthread.php?p=45349 MINECRAFT IN ALICE: http://alice.org/community/showthread.php?p=48208 My Stupid Animations: http://alice.org/community/album.php?albumid=119

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge