Computer Science Canada Rand.Int Replication |
Author: | Fashoomp [ Mon May 21, 2007 5:00 pm ] |
Post subject: | Rand.Int Replication |
how can i use randint, so it gives my a random pattern of numbers, so it does not give me the same value twice. I want all the values between 1 and 10, given to me, in a random order. |
Author: | Clayton [ Mon May 21, 2007 5:09 pm ] |
Post subject: | RE:Rand.Int Replication |
you'll have to loop until you get all of the numbers. Now, you'll need to have some sort of array to hold all of the numbers that you've gotten. Just compare that array of numbers to the number you get from Rand.Int(), and if that number is not in the array, display it, and then add that number to the array. |
Author: | Saad [ Mon May 21, 2007 5:19 pm ] | ||
Post subject: | Re: Rand.Int Replication | ||
This is the fastest way i could come up with.
Edit: Fixed some spelling mistakes |
Author: | Carey [ Tue May 22, 2007 9:11 am ] | ||
Post subject: | Re: Rand.Int Replication | ||
Here is a shorter and more efficiant method.
|
Author: | Saad [ Tue May 22, 2007 2:17 pm ] |
Post subject: | Re: Rand.Int Replication |
Is it me or does Rand.Int use system time to generate a random number, since if you ran the prog 10 times in .5 sec all the random values would be the same |
Author: | DIIST [ Tue May 22, 2007 3:15 pm ] | ||
Post subject: | Re: Rand.Int Replication | ||
A recursive solution:
Not the best but it works for the most part . a100 @ Tue May 22, 2007 2:17 pm wrote: Is it me or does Rand.Int use system time to generate a random number, since if you ran the prog 10 times in .5 sec all the random values would be the same
Yes i do believe system time is used as the random seed generator. But you can easily reset it by doing randomize (I think). Its all machine dependant. Some machines, regardless of what you do may still spit out the same set of value again and again at each runtime. |
Author: | Cervantes [ Tue May 22, 2007 5:56 pm ] |
Post subject: | RE:Rand.Int Replication |
I'm pretty sure randomize is obsolete in the newer versions of Turing. Yes, the system time is used. Theoretically, I think it uses milliseconds, so you probably shouldn't be seeing any patterns. However, practically, I've seen them too. Clayton wrote: you'll have to loop until you get all of the numbers. Now, you'll need to have some sort of array to hold all of the numbers that you've gotten. Just compare that array of numbers to the number you get from Rand.Int(), and if that number is not in the array, display it, and then add that number to the array.
I can't believe you just said this. This scheme can take an unbounded amount of time. This really sucks, when you compare it to the better solution, which takes exactly 10 iterations, where each iteration requires a little search (could easily be done in log n time, if you do a binary search). |
Author: | Clayton [ Tue May 22, 2007 6:25 pm ] |
Post subject: | RE:Rand.Int Replication |
I'm not sure if you're thinking about this the same way I was thinking about it when I wrote it. Perhaps I just didn't convey my message clearly. For that, I apologize. |