Alice Community

Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   how do i make a random number not appear twice (http://www.alice.org/community/showthread.php?t=7104)

nickster654 08-16-2011 09:07 PM

how do i make a random number not appear twice
 
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 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 [I]help[/I] 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?:confused:

kidum2011 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 08-17-2011 10:20 PM

[QUOTE=legolizard;40800]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 [I]help[/I] 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?:confused:[/QUOTE]

yeaa that makes perfect sense, but it would no take foreverrrr in m situation

Jabadahut50 08-19-2011 07:41 PM

solution to the solution
 
[QUOTE=nickster654;40823]yeaa that makes perfect sense, but it would no take foreverrrr in m situation[/QUOTE]

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 08-19-2011 08:52 PM

make 2 variables ([I]a, b[/I]).
set [I]a[/I] to random number
set [I]a[/I] to [B]b[/B]
do whatever with the variable you want
set [I]a[/I] to random number
if [I]a[/I] is equal to [I]b[/I]
repeat
if not continue


All times are GMT -5. The time now is 08:46 PM.

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