SA-MP Forums Archive
Random value from array. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Random value from array. (/showthread.php?tid=241642)



Random value from array. - kLx - 18.03.2011

Hello!

So, I have this system, where it generates random questions.
There is one problem - how could I generate a question, that hasn't been given yet?

For example, I have pvars: t_que[1-5];
and they store the questions they already been given, and I also have the maximum number of questions that exists (15), so how could i select a random value from 15, that isn't t_que[1-5] pvars?


Re: Random value from array. - Mike Garber - 18.03.2011

Just made this;

pawn Код:
RandomValue()
{
    new value = random(15);
    if(value >= 1 && value <= 5 || value == 0){ return RandomValue(); }
    return value;
}
pawn Код:
// USAGE
printf("%d",RandomValue());

integer = RandomValue();
Tested it here (223 times or somethin);

Код:
[14:50:03] 9
[14:50:03] 11
[14:50:03] 14
[14:50:03] 8
[14:50:03] 6
[14:50:03] 10
[14:50:03] 7
[14:50:03] 6
[14:50:03] 9
[14:50:03] 7
[14:50:03] 10
[14:50:03] 11
[14:50:03] 7
[14:50:03] 14
[14:50:03] 8
[14:50:03] 11
[14:50:03] 7
[14:50:03] 7
[14:50:03] 14
[14:50:03] 6
[14:50:03] 12
[14:50:03] 14
[14:50:03] 14
[14:50:03] 11
[14:50:03] 7
[14:50:03] 13
[14:50:03] 8
[14:50:03] 7
[14:50:03] 9
[14:50:03] 13
[14:50:03] 11
[14:50:03] 14
[14:50:03] 7
[14:50:03] 8
[14:50:03] 12
[14:50:03] 13
[14:50:03] 9
[14:50:03] 9
[14:50:03] 10
[14:50:03] 7
[14:50:03] 10
[14:50:03] 12
[14:50:03] 13
[14:50:03] 11
[14:50:03] 9
[14:50:03] 10
[14:50:03] 10
[14:50:03] 11
[14:50:03] 13
[14:50:03] 9
[14:50:03] 9
[14:50:03] 13
[14:50:03] 10
[14:50:03] 10
[14:50:03] 9
[14:50:03] 14
[14:50:03] 7
[14:50:03] 14
[14:50:03] 13
[14:50:03] 14
[14:50:03] 7
[14:50:03] 8
[14:50:03] 7
[14:50:03] 9
[14:50:03] 8
[14:50:03] 14
[14:50:03] 11
[14:50:03] 13
[14:50:03] 9
[14:50:03] 9
[14:50:03] 11
[14:50:03] 14
[14:50:03] 11
[14:50:03] 9
[14:50:03] 13
[14:50:03] 6
[14:50:03] 6
[14:50:03] 10
[14:50:03] 14
[14:50:03] 13
[14:50:03] 8
[14:50:03] 7
[14:50:03] 12
[14:50:03] 13
[14:50:03] 12
[14:50:03] 13
[14:50:03] 9
[14:50:03] 6
[14:50:03] 9
[14:50:03] 14
[14:50:03] 8
[14:50:03] 8
[14:50:03] 14
[14:50:03] 8
[14:50:03] 13
[14:50:03] 11
[14:50:03] 9
[14:50:03] 13
[14:50:03] 14
[14:50:03] 9
[14:50:03] 10
[14:50:03] 10
[14:50:03] 11
[14:50:03] 14
[14:50:03] 11
[14:50:03] 10
[14:50:03] 10
[14:50:03] 13
[14:50:03] 11
[14:50:03] 10
[14:50:03] 13
[14:50:03] 6
[14:50:03] 11
[14:50:03] 14
[14:50:03] 10
[14:50:03] 6
[14:50:03] 11
[14:50:03] 8
[14:50:03] 10
[14:50:03] 9
[14:50:03] 11
[14:50:03] 13
[14:50:03] 13
[14:50:03] 12
[14:50:03] 9
[14:50:03] 13
[14:50:03] 10
[14:50:03] 12
[14:50:03] 9
[14:50:03] 13
[14:50:03] 11
[14:50:03] 12
[14:50:03] 12
[14:50:03] 9
[14:50:03] 9
[14:50:03] 12
[14:50:03] 9
[14:50:03] 13
[14:50:03] 6
[14:50:03] 6
[14:50:03] 13
[14:50:03] 8
[14:50:03] 13
[14:50:03] 8
[14:50:03] 9
[14:50:03] 8
[14:50:03] 13
[14:50:03] 6
[14:50:03] 9
[14:50:03] 8
[14:50:03] 14
[14:50:03] 7
[14:50:03] 8
[14:50:03] 12
[14:50:03] 8
[14:50:03] 7
[14:50:03] 10
[14:50:03] 9
[14:50:03] 11
[14:50:03] 13
[14:50:03] 6
[14:50:03] 7
[14:50:03] 10
[14:50:03] 9
[14:50:03] 13
[14:50:03] 10
[14:50:03] 13
[14:50:03] 11
[14:50:03] 10
[14:50:03] 10
[14:50:03] 14
[14:50:03] 12
[14:50:03] 12
[14:50:03] 8
[14:50:03] 6
[14:50:03] 9
[14:50:03] 14
[14:50:03] 13
[14:50:03] 14
[14:50:03] 7
[14:50:03] 7
[14:50:03] 14
[14:50:03] 9
[14:50:03] 14
[14:50:03] 7
[14:50:03] 7
[14:50:03] 7
[14:50:03] 10
[14:50:03] 14
[14:50:03] 9
[14:50:03] 7
[14:50:03] 7
[14:50:03] 12
[14:50:03] 10
[14:50:03] 8
[14:50:03] 7
[14:50:03] 9
[14:50:03] 8
[14:50:03] 10
[14:50:03] 11
[14:50:03] 6
[14:50:03] 12
[14:50:03] 9
[14:50:03] 10
[14:50:03] 6
[14:50:03] 12
[14:50:03] 11
[14:50:03] 11
[14:50:03] 9
[14:50:03] 14
[14:50:03] 12
[14:50:03] 8
[14:50:03] 10
[14:50:03] 8
[14:50:03] 14
[14:50:03] 10
[14:50:03] 12
[14:50:03] 10
[14:50:03] 9
[14:50:03] 6
[14:50:03] 6
[14:50:03] 11
[14:50:03] 6
[14:50:03] 6