random numbers bug or?
#1

PHP код:
CMD:test(playerid,params[]){
new 
result random(15-5)+5*-1;
format(String,sizeof(String),"Result = %i",result);
MSG(playerid,-1,String);
return 
1;} 
I want it to gimme random number between -5 to -15, why it's giving me sometimes numbers above -5 (means like -3 or even postive numbers such as 4 etc)
Reply
#2

new randomNumber = random(max-min)+min;
Reply
#3

Quote:
Originally Posted by Trucido
Посмотреть сообщение
new randomNumber = random(max-min)+min;
bro... that would give me a postive number between 5 to 15, i want -5 to -15
Reply
#4

new result = random(15-5)+5*-1 = random(10)-5
Learn the math priorities. a fix would be simply -random(15-5)-5;
Reply
#5

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
new result = random(15-5)+5*-1 = random(10)-5
Learn the math priorities. a fix would be simply -random(15-5)-5;
hehe ye i thought about random((15-5)-5)*1 etc but it gave me some bugs, thank you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)