How to create randoms with exceptions
#3

PHP код:
randomex(maxexception = -1)
{
if(
exception == -1) return random(max);
new 
random(max 1);
return (
== exception r);

Way simpler than the one above. But only works for preventing the same value 2 times. This can still happen: 2, 3, 2, 3, 2, 3 etc.

If your first result was 2 (out of 0-3), it will get a random value of 0-2. If the value is your last value, it will add one, else take that value. If the first value was the maximum value, it cannot be chosen again (hence "max - 1").
Reply


Messages In This Thread
How to create randoms with exceptions - by coool - 17.12.2016, 12:44
Re: How to create randoms with exceptions - by Dayrion - 17.12.2016, 12:54
Re: How to create randoms with exceptions - by NaS - 17.12.2016, 15:47
Re: How to create randoms with exceptions - by coool - 17.12.2016, 15:58
Re: How to create randoms with exceptions - by SickAttack - 17.12.2016, 16:07
Re: How to create randoms with exceptions - by NaS - 17.12.2016, 16:56

Forum Jump:


Users browsing this thread: 3 Guest(s)