Author |
Message |
Tony
|
|
|
|
|
Sponsor Sponsor
|
|
|
soulgnat
|
Posted: Wed Jan 07, 2004 8:35 pm Post subject: can you explain your code? |
|
|
can you explain a code? im working on a similar thing but mine is for a school assignment to produce winning numbers on a chance game..thanx so much |
|
|
|
|
|
Tony
|
Posted: Wed Jan 07, 2004 10:30 pm Post subject: (No subject) |
|
|
well the explonation was done somewhere in [turing help], I just liked the piece of code I wrote so I made another post here... anyways, explanaton is as follows:
it is extreamly inefficient to just randomly keep on picking the number and hope it's a unique (have not been picked before). If you're after 10 unique numbers, you have just 1/10 chance to pick that last number out. Now if you need randomly sort a list of 100 numbers... well... it will take you a long while with 1/100 chance
So what you do is you select the position of the number in the array of numbers left, rether then the number itself. After each pick, your array list is reduced by one. This continues on untill neeed amount of numbers were picked.
This is much more efficient since the array contains only the numbers that were not yet picked, so you always have 1/1 chance to get the number you want |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
shorthair
|
Posted: Tue Jan 13, 2004 7:15 pm Post subject: (No subject) |
|
|
Tony if you had joined yeterday and that program was writin with your eyes closed on a comadorer 64 , i would give you all my bits but dude , |
|
|
|
|
|
kanetix
|
Posted: Tue Jan 13, 2004 11:25 pm Post subject: newb question |
|
|
I know its not really on topic but for a school project i have to randomize 10 words and the user has to arrange it in alphabetical order, is that possible?
also wut does put numbers (randN) <--- wut does the randN in the brackets do? |
|
|
|
|
|
Tony
|
Posted: Tue Jan 13, 2004 11:40 pm Post subject: (No subject) |
|
|
(randN) is the index of the array. There're some tutorials available on arrays in [Turing Tutorials].
to arrange words alphabetically, you want a to sort them (easiest is the bubble sort) You can use Search to find the source code for it |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Dragsz
|
Posted: Tue Mar 17, 2015 8:02 pm Post subject: RE:[source code] Random Numbers List |
|
|
Is there any way to move "put numbers (randN)" out of the for loop? |
|
|
|
|
|
Insectoid
|
Posted: Thu Mar 19, 2015 3:20 pm Post subject: RE:[source code] Random Numbers List |
|
|
Sure, just cut & paste the code to a line outside the loop. I'm not sure that would be so useful though. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|