Computer Science Canada Random Number Sorting Issues |
Author: | w00t [ Mon Dec 20, 2004 9:24 am ] |
Post subject: | Random Number Sorting Issues |
Hey, Im having some trouble sorting an array i have in my program for school. Its an imitation of a lottery and i have an array filled with 6 random numbers, but i need to sort them -edit - Code is now useless |
Author: | Cervantes [ Mon Dec 20, 2004 9:53 am ] |
Post subject: | |
Yes, looks like your sorting method works. It seems to me that it is only sorting 5 of the numbers from 1 to 6 (ie. 1, 2, 3, 5, & 6 -or- 1,3,4,5,&6) and 49. So, we need to fix your random number generation, not your sorting. First, change your array from 1 .. 49 to 1 .. 6. Then, we want to create 6 random numbers (from 1 to 49) and assign them to our intnumbers array. But, each time we create a random number, we must check to see that that number is not = to any of the previous random numbers that we've made. Use a loop and an exit command to do that. Essentially, you'll have your loop, then your random number generation line, then a little more complex code to check if the current element of the array is equal to any of the previous elements of the array. I suggest making a function to do this, but it's not necessary. I hope you can understand that. Post any further questions if you have them ![]() |
Author: | w00t [ Mon Dec 20, 2004 10:10 am ] |
Post subject: | |
sry, im slow today, could u explain a little more Quote: Then, we want to create 6 random numbers (from 1 to 49) and assign them to our intnumbers array.
its one of those days were I'm completly disoriented, so im lost here, i made this last night when it made sense. How do i do this. I feel like an uber noob asking but oh well.. w00t |
Author: | Cervantes [ Mon Dec 20, 2004 10:15 am ] |
Post subject: | |
Your questions are welcome. ![]() for each element of the array, make a Rand.Int. |
Author: | w00t [ Mon Dec 20, 2004 5:41 pm ] |
Post subject: | |
Thanks alot, i have it working !! yay ! now back to programming my game ![]() !WHEN FURBIES ATTACK! lol, thanks alot Cervantes, greatly appreciated! w00t w00t |
Author: | Drakain Zeil [ Wed Dec 22, 2004 5:24 pm ] |
Post subject: | |
That's funny, I just did a lotto number program for school, it's on my hard drive at school however... so I won't have access till jan. when school stars up again. edit: Hmm, this is rather old, I just noticed that... |