My Random Number Generator is producing small numbers -
i'm trying create "random" number generator online game.
i want create number purely based on positions , stats of players, , based on small counter increments 1 each step in controller.
here's code create "seed" , function use seed generate random number 0 -> max non-inclusive:
function generate_seed(){ var num = 1; for(var = 0; < number_of_players; i++){ var prevnum = num; num++; } num+=obj_controller.randstep; //randstep variable gets incremented 1 in controller object each step //loops through players with(obj_player){ if(x % 2){num+=x;} else {num-=x;} if(y % 2){num+=y;} else {num-=y;} if(hp % 2){num+=hp;} else {num-=hp;} if(randstep % 2){num+=randstep;} else {num-=randstep;} } return abs(num); } function random(var max){ //generate synced random number 0 -> max, not include max var seeder = synced_random_generate(); seeder+= max * 5; //make sure seed greater max return seeder mod max; }
the thing is, sort of works, if do: random(20000);
it return small number relative max (20,000).
i've never seen return number greater 3000. strange.
does know what's wrong or possible simpler way generate random number based on player positions/stats , incrementing counter in controller?
found great solution online:
int rand1(int lim) { static long = 100001; = (a * 125) % 2796203; return ((a % lim) + 1); }
Comments
Post a Comment