Question about timers
#1

Hello, it is possible to make a timer that is random from 20 seconds to 60 seconds?

pawn Код:
SetTimerEx("TestTimer", 30000, false, "i", playerid);
Reply
#2

PHP код:
SetTimerEx("TestTimer"random(60000-20000+1)+20000false"i"playerid); 
Reply
#3

Yes:

pawn Код:
SetTimerEx("TestTimer", 20000+(random(40)*1000), false, "i", playerid);
Reply
#4

Thank you
Reply
#5

Quote:
Originally Posted by diego200052
Посмотреть сообщение
Yes:

pawn Код:
SetTimerEx("TestTimer", 20000+(random(40)*1000), false, "i", playerid);
you know that wont work right? +1 is also required
Reply
#6

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
you know that wont work right? +1 is also required
Why?
Reply
#7

Quote:
Originally Posted by diego200052
Посмотреть сообщение
Why?
i can simply tell with example
random(2) gives two possible outputs 0 and 1 that means random(x) gives 0 to x-1 numbers
so to find range of random the programm should be like this
random(upperlimit-lowerlimit+1)+lowerlmit
for eg in this case for finding the random in range 20 to 60 seconds
it should be like this
random(60000-20000+1)+20000
or
random(40000+1)+20000
random(40000) will only give values up to 39 seconds and that plus 20 gives 59(maximum possible) not 60
so to get 60 we adds 1 to it
random(40001)+20000 give MAX-60000 or 60 seconds and MIN-200000 or 20 seconds
Reply
#8

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
i can simply tell with example
random(2) gives two possible outputs 0 and 1 that means random(x) gives 0 to x-1 numbers
so to find range of random the programm should be like this
random(upperlimit-lowerlimit+1)+lowerlmit
for eg in this case for finding the random in range 20 to 60 seconds
it should be like this
random(60000-20000+1)+20000
or
random(40000+1)+20000
random(40000) will only give values up to 39 seconds and that plus 20 gives 59(maximum possible) not 60
so to get 60 we adds 1 to it
random(40001)+20000 give MAX-60000 or 60 seconds and MIN-200000 or 20 seconds
Thanks, I understood perfectly
Reply
#9

pawn Код:
SetTimerEx("TestTimer", (random(40001) + 20000), false, "i", playerid);
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)