Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
how do i make a random number not appear twice
Old
nickster654
Senior Member
 
Status: Offline
Posts: 180
Join Date: Feb 2011
Location: nickster12345678@gmail.com
Default 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?
   
Reply With Quote
Old
legolizard
Senior Member
 
legolizard's Avatar
 
Status: Offline
Posts: 242
Join Date: Jan 2011
Location: Aboard the Hyperion escaping the zerg.
Default 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
   
Reply With Quote
Old
kidum2011
Junior Member
 
Status: Offline
Posts: 2
Join Date: Aug 2011
Location: Israel
Default 08-17-2011, 06:51 AM

you can create an array for the whole numbers, and to set empty each number that was taken.
   
Reply With Quote
Old
nickster654
Senior Member
 
Status: Offline
Posts: 180
Join Date: Feb 2011
Location: nickster12345678@gmail.com
Default 08-17-2011, 10:20 PM

Quote:
Originally Posted by legolizard View Post
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
   
Reply With Quote
solution to the solution
Old
Jabadahut50
Member
 
Status: Offline
Posts: 19
Join Date: Aug 2011
Default solution to the solution - 08-19-2011, 07:41 PM

Quote:
Originally Posted by nickster654 View Post
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.
   
Reply With Quote
Old
InsertName
Senior Member
 
InsertName's Avatar
 
Status: Offline
Posts: 341
Join Date: Jun 2011
Location: In a house
Default 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
   
Reply With Quote
Reply

Thread Tools
Display Modes

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 Jump



Copyright ©2020, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.