Ok, so what we’re saying here, is that if you’re at the first entry of the array, you want to guarntee zero won’t come up.
What I would do is put this in the loop:
if (t==0) {
int r = Mathf.Clamp(Random.Range(t,playerAmount),1f,playerAmount)
}
else {
//where rest of code goes
}
This would all be inside your for loop.
I think that will do what you want, not sure if it’ll catch on types with the floats. But what that should do is clamp that random value to something 1 or over and less than playerAmount (which is the maximum anyway) and since the if statement will only be called on the first pass through the loop, it won’t affect the other run throughs. I’m not sure exactly how you’re storing everything, so I didn’t include that in the code I wrote.
Thanks for your thoughts on this Slev, but here’s the problem: I’m ALSO no allowed to let cycles[1] be 1, cycles[2] be 2 and cycles[3] be 3… Any ideas?
Hm, ok let me just get this clarified before I get my mind all “method coding,” basically we can never allow cycles[×] == x where x is any int that is a subset of our initial array?
Ok, basically all we need to do then is prevent t from equaling r ever.
We can just put in a quick catch that says:
while (t==r) {
r = Random.Range(t, playerAmount);
}
Basically what that should do is force r to re-roll if it matches t. Now it seems like these are matching up based on the r value in terms of cycle, but the principle should apply, with a little tweaking perhaps.
You could put in a catch for that, but, at this point, you may be better off not randomly generating since it seems to be a fairly strict randomization, otherwise we could put a catch like when t>1 to prevent that we can simply always force entry index 1 or 2 to be 3, that way it’s pseudo random.