C
C#5mo ago
yeetyoottoot

does this work for choosing a random item in a list then removing it then choosing again

int randomNumber = Random.Range(spawnInts[0], spawnInts.Count);
spawnInts.RemoveAt(randomNumber);
randomNumber = Random.Range(spawnInts[0], spawnInts.Count);
int randomNumber = Random.Range(spawnInts[0], spawnInts.Count);
spawnInts.RemoveAt(randomNumber);
randomNumber = Random.Range(spawnInts[0], spawnInts.Count);
does this make it so when i choose a 2nd time i cant get the number i removed
5 Replies
Jimmacle
Jimmacle5mo ago
is this unity? if so, according to the https://docs.unity3d.com/ScriptReference/Random.Range.html page this function doesn't work the way you think it does Random.Range generates a number using a min and max bound, it doesn't select numbers out of a list
SY
SY5mo ago
I think it still do what he is trying to do this might give u the same number u removed for the first time
Pobiega
Pobiega5mo ago
not entirely true spawnInts[0], spawnInts.Count unless that value at spawnInts[0] is always 0, this wont do whats expected
SY
SY5mo ago
c#
int randomNumber = Random.Range(0, spawnInts.Count - 1); // actually like this so it doesn't go out of index
c#
int randomNumber = Random.Range(0, spawnInts.Count - 1); // actually like this so it doesn't go out of index
Jimmacle
Jimmacle5mo ago
so my understanding of this post is: @yeetyoottoot wants to pick a number from an existing list of numbers Random.Range generates a floating point number between two numbers so, this is not the correct api to use for that
Want results from more Discord servers?
Add your server
More Posts