ID:272258
 
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?
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.
In response to Garthor
Im kinda new at coding so how would I do that? If you dont mind showing, please do.
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
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
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
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.