ID:272258
![]() May 17 2008, 1:35 pm
|
|
Is it possable to make like, a rand/prob number thing, were the numbers can't be used twice?? And if it is, would anyone mind explaining?
|
![]() May 17 2008, 1:45 pm
|
|
To do this, you would generate a list of numbers, pick from that, and remove what you just picked. It works the same as a deck of cards.
|
That would easily be quite some extra overhead if you had a big number range; you really don't need a list element per every number from 1 to 100 (for instance) for this, unless you're choosing 100 different numbers. Instead, you should just repeat the rand()/pick()/etc every time is produces a value that was used before (so you'd store past values in a list). You could also possibly optimize it more in some cases so it will do less unneeded processing, but really the above already does the job.
Renjo Kujika wrote: Im kinda new at coding so how would I do that? If you dont mind showing, please do. (If you're new to lists, you should read up on them in the DM Reference and DM Guide) That would be done by creating a list, then calling rand() in a loop, and adding the number it returns to the list only if it isn't already there. You could make a proc for that; my_randoms(min,max,num) //this proc takes 3 arguments: first like rand()'s arguments + how many numbers you want. |
That would easily be quite some extra overhead if you had a big number range; you really don't need a list element per every number from 1 to 100 (for instance) for this, unless you're choosing 100 different numbers. Instead, you should just repeat the rand()/pick()/etc every time is produces a value that was used before (so you'd store past values in a list). You could also optimize it more in some cases so it will do less unneeded processing, but the above already does the job.
Renjo Kujika wrote: Im kinda new at coding so how would I do that? If you dont mind showing, please do. (If you're new to lists, you should read up on them in the DM Reference and DM Guide) What I said above would be done by creating a list, then calling rand() in a loop, and adding the number it returns to the list only if it isn't already there. You could make a proc for that; my_randoms(min,max,num) //this proc takes 3 arguments: first like rand()'s arguments + how many numbers you want. |
That would easily be quite some extra overhead if you had a big number range; you really don't need a list element per every number from 1 to 100 (for instance) for this, unless you're choosing 100 different numbers. Instead, you should just repeat the rand()/pick()/etc every time is produces a value that was used before (so you'd store past values in a list). You could also optimize it more in some cases so it will do less unneeded processing, but the above already does the job.
Renjo Kujika wrote: Im kinda new at coding so how would I do that? If you dont mind showing, please do. (If you're new to lists, you should read up on them in the DM Reference and DM Guide) What I said above would be done by creating a list, then calling rand() in a loop, and adding the number it returns to the list only if it isn't already there. You could make a proc for that; my_randoms(min,max,num) //this proc takes 3 arguments: first like rand()'s arguments + how many numbers you want. |