ID:272258   May 17 2008, 12: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, 12: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.
 May 17 2008, 3:30 pm In response to Garthor Im kinda new at coding so how would I do that? If you dont mind showing, please do.
 May 17 2008, 6:33 pm In response to Garthor 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. var/list/numbers = new //initialize a new list while(numbers.len < num) //loop until our list has enough numbers in it var/N = rand(min,max) //generate a random number if(!(N in numbers)) //if the number isn't already in the numbers list numbers += N //add it (also increasing the length of the list in the process) return numbers //return the list to the proc caller ```
 May 17 2008, 6:35 pm In response to Garthor 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. var/list/numbers = new //initialize a new list while(numbers.len < num) //loop until our list has enough numbers in it var/N = rand(min,max) //generate a random number if(!(N in numbers)) //if the number isn't already in the numbers list numbers += N //add it (also increasing the length of the list in the process) return numbers //return the list to the proc caller ```
 May 17 2008, 6:36 pm In response to Garthor 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. var/list/numbers = new //initialize a new list while(numbers.len < num) //loop until our list has enough numbers in it var/N = rand(min,max) //generate a random number if(!(N in numbers)) //if the number isn't already in the numbers list numbers += N //add it (also increasing the length of the list in the process) return numbers //return the list to the proc caller ```
 May 17 2008, 6:43 pm In response to Kaioken And yours has an indeterminate amount of overhead. It could be done in num iterations, it could be done in a million iterations, and it could never finish (if num > max-min). "Guess and check" is always the wrong choice.