18.03.2012, 04:45
yeah thats the trouble with any random function
this has been a problem for me for years in MANY languages.
Im actually a newbie to pawn but the fundamentals still apply
im sure what your doing is limiting you to just 3
but just as a test to know it is in fact random
maybe make the array with 12 ids (just for testing)
this would give a 8.3% chance of each car being spawned.
they can even be the same ids just over and over.
i think the last time i had this problem was with a webpage (vbscript)
ill see if i can dig that up and see what kind of logical solution i came up with back then.
one thing that may or may not help (this would depend on pawns underlying logic)
is the code i posted uses the same rand var for all three spawns
maybe remove that var all together and use it inline like
i know some language use a tick count to calculate the random number(im not sure of all the logic but)
im not sure how pawn does there random.. sorry, but if so this would explain the same spawn as the code
its excuted so quickly..
let me know how this turned out for you
im interested to know the results.
regards,
edit:
also if you respawned the cars it will keep the model id always.
once you add the vehicle you cannot change the model id that im aware of,
respawning the car would do just that,
so scratch that test all together
a better test would be to use a loop and print the random number maybe 50 times...
this will tell all
note i did this and my numbers come out looking like...
401
401
401
405
405
404
405
401
405
405
404
405
401 ...... and on and on
so as you see in the first 3 tried its found the same number..
hope this helps
this has been a problem for me for years in MANY languages.
Im actually a newbie to pawn but the fundamentals still apply
im sure what your doing is limiting you to just 3
but just as a test to know it is in fact random
maybe make the array with 12 ids (just for testing)
this would give a 8.3% chance of each car being spawned.
they can even be the same ids just over and over.
i think the last time i had this problem was with a webpage (vbscript)
ill see if i can dig that up and see what kind of logical solution i came up with back then.
one thing that may or may not help (this would depend on pawns underlying logic)
is the code i posted uses the same rand var for all three spawns
maybe remove that var all together and use it inline like
pawn Код:
new RandomVehicles[] =
{
404,
401,
405
};
AddStaticVehicleEx(RandomVehicles[random(sizeof(RandomVehicles))],-901.9831,2687.4890,42.4714,43.9074,-1,0,60000); // RandCar1
AddStaticVehicleEx(RandomVehicles[random(sizeof(RandomVehicles))],-901.9831,2687.4890,42.4714,43.9074,-1,0,60000); // RandCar2
AddStaticVehicleEx(RandomVehicles[random(sizeof(RandomVehicles))],-901.9831,2687.4890,42.4714,43.9074,-1,0,60000); // RandCar3
im not sure how pawn does there random.. sorry, but if so this would explain the same spawn as the code
its excuted so quickly..
let me know how this turned out for you
im interested to know the results.
regards,
edit:
also if you respawned the cars it will keep the model id always.
once you add the vehicle you cannot change the model id that im aware of,
respawning the car would do just that,
so scratch that test all together
a better test would be to use a loop and print the random number maybe 50 times...
this will tell all
pawn Код:
new RandomVehicles[] =
{
404,
401,
405
};
new rdTest;
for(rdTest=0;rdTest<50;rdTest++){
printf("%i",RandomVehicles[random(sizeof(RandomVehicles))]);
}
401
401
401
405
405
404
405
401
405
405
404
405
401 ...... and on and on
so as you see in the first 3 tried its found the same number..
hope this helps