Pick 4 random numbers 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)
+--- Thread: Pick 4 random numbers from array. (
/showthread.php?tid=605398)
Pick 4 random numbers from array. -
MRM - 18.04.2016
Hi,
How to pick 4 random numbers from array and not repeat?
pawn Код:
new arrVehRandCP[28][1] =
{
411,
424,
413,
489,
589,
477,
404,
561,
493,
470,
452,
562,
486,
571,
558,
527,
426,
402,
534,
480,
551,
492,
400,
567,
575,
466,
412,
418
};
Thanks.
Re: Pick 4 random numbers from array. -
Jefff - 18.04.2016
pawn Код:
PickNumbers(array[], s_size = sizeof(array))
{
static arrVehRandCP[] =
{
411,
424,
413,
489,
589,
477,
404,
561,
493,
470,
452,
562,
486,
571,
558,
527,
426,
402,
534,
480,
551,
492,
400,
567,
575,
466,
412,
418
};
if(s_size > sizeof(arrVehRandCP))
s_size = sizeof(arrVehRandCP);
new TemparrVehRandCP[sizeof(arrVehRandCP)], rnd;
TemparrVehRandCP = arrVehRandCP;
while(s_size > 0)
{
rnd = random(sizeof(arrVehRandCP));
if(TemparrVehRandCP[rnd])
{
array[--s_size] = TemparrVehRandCP[rnd];
TemparrVehRandCP[rnd] = 0;
}
}
}
Usage:
pawn Код:
new My_Number[4];
PickNumbers(My_Number);
for(new i=0; i < sizeof(My_Number); i++)
printf("%d. %d",i,My_Number[i]);
Re: Pick 4 random numbers from array. -
MRM - 18.04.2016
Thank you, It is perfect
.
When players enter the checkpoint :
pawn Код:
new Veh = GetPlayerVehicleID(playerid);
new VehModel = GetVehicleModel(Veh);
if(My_Number[i] == VehModel)
{
// <===== I want only the My_Number[i] again to be random.
SendClientMessage(playerid,-1,"Test.");
return 1;
}
Thanks .
Re: Pick 4 random numbers from array. -
MRM - 19.04.2016
anyone ?