Computer Science Canada HELP!!! Random numbers and an array |
Author: | python_4 [ Mon Jan 12, 2004 6:29 pm ] |
Post subject: | HELP!!! Random numbers and an array |
Hey guys, I need help with my project here. The problem is that I cannot make a program that will randomly select 9 numbers out of 1..20 and not select the selected numbers again. That is, i want help in creating a program which will select 9 DIFFERENT numbers from 1.. 20 and store it in different variables or an array, so that I can later use the array to call upon text files. That is, each number between 1..20 represents a text file. Please take into consideration that I must be able to use the numbers to call upon TEXT files. I would really really really appreciate if someone would help me out. |
Author: | Tony [ Mon Jan 12, 2004 6:33 pm ] |
Post subject: | |
seems you're new, so I'll show you around a bit 8) There's this very interesting place on this forum called [Turing Source Code] The interesting thing is that it has a bunch of writen code that could have just what you're looking for ![]() such as this Random List Generator, check it out - it's just what you're looking for |
Author: | McKenzie [ Mon Jan 12, 2004 6:36 pm ] |
Post subject: | |
So it sounds like you are making some trivia game and you want random catagories. You will need two arrays One to store your random picks and one to keep track of the spots you have used. Run a for loop from 1 to 9. Inside the for you must ensure that you randomly pick a unique number. What you need is a loop. You will keep looping until you randomly pick a number that has not been picked, then record that it has been picked. |
Author: | python_4 [ Mon Jan 12, 2004 6:42 pm ] |
Post subject: | Thank you |
Thank you very much, that was exactly what i was looking for. I really appreciate for your help and time. |
Author: | Tony [ Mon Jan 12, 2004 9:52 pm ] |
Post subject: | |
McKenzie wrote: randomly pick a number that has not been picked
![]() ![]() I mean you're a teacher... shouldn't you like promote efficiency and correct programming approaches or something ![]() |
Author: | McKenzie [ Mon Jan 12, 2004 11:16 pm ] | ||
Post subject: | |||
yer kiddin right? Run your program and check the number of milliseconds, then run mine. Hmmm ... 190 vs 14 on my computer
|
Author: | Tony [ Mon Jan 12, 2004 11:48 pm ] |
Post subject: | |
![]() ![]() |
Author: | McKenzie [ Tue Jan 13, 2004 9:50 am ] | ||
Post subject: | |||
Oh you mean like:
Run it, it's O(n) |
Author: | McKenzie [ Tue Jan 13, 2004 4:07 pm ] |
Post subject: | |
Hey Tony, I tried to time yours like mine, it kinda freezes. |
Author: | Cervantes [ Tue Jan 13, 2004 4:14 pm ] |
Post subject: | |
go Mckenzie!! no.. go tony!! *gives up and does the wave* |
Author: | Tony [ Tue Jan 13, 2004 4:18 pm ] |
Post subject: | |
hahaha ![]() ![]() ![]() I think we need to continue this discussion in another language that doesn't suck as much as turing ![]() |
Author: | Cervantes [ Tue Jan 13, 2004 4:21 pm ] |
Post subject: | |
*points at tony* BLASPHEMY!!!! go Mckenzie!! go mckenzie! |
Author: | McKenzie [ Tue Jan 13, 2004 4:41 pm ] |
Post subject: | |
Well, which one would you prefer? QBASIC, Fortran, Pascal, Javascript, C, C++, Miranda, Prolog, simscript, Smalltalk, 8088 ASM, Visual Basic, GPSS, COBOL??? P.S. please don't pick COBOL (ouch) |
Author: | Tony [ Tue Jan 13, 2004 6:30 pm ] |
Post subject: | |
haha ![]() |
Author: | python_4 [ Tue Jan 13, 2004 7:07 pm ] |
Post subject: | bitmaps |
Bitmaps |
Author: | Maverick [ Tue Jan 13, 2004 7:23 pm ] |
Post subject: | |
Hmm I get it? ![]() ![]() |
Author: | Andy [ Tue Jan 13, 2004 8:06 pm ] |
Post subject: | |
lol mickey doesnt know java |
Author: | McKenzie [ Tue Jan 13, 2004 8:56 pm ] | ||
Post subject: | |||
![]()
for 100000 elements that makes it of order n. 12.3 n is of order n. |
Author: | Dauntless [ Tue Jan 13, 2004 9:01 pm ] |
Post subject: | |
Help!! Random numbers and an array! or How helping a new programmer can turn into a battle of the titans. |
Author: | Tony [ Tue Jan 13, 2004 9:05 pm ] |
Post subject: | |
![]() bah... thats what I get for theoretical programming ![]() |
Author: | Tony [ Sat Jan 17, 2004 8:49 pm ] |
Post subject: | |
ha, I knew I was right ![]() I was looking at my code and though - "what the hell was that guy thinking?" then I realized it was my code and fixed it. Edited version of algorythm is found in the same place the problem was how I was shifting my array. I used to throw out one element and moved everything to the left from that point on. But then (now) I figured that there was no point in keeping the remainding numbers in order so I just moved the last element in place of one to be deleted ![]() the result? this cut down the execution speed to just 2% of previous algorythm (tested at size=1000) ![]() McKenzie - would you like to run some more tests now ![]() |