[HELP] Random numbers?
#1

Hey,
How could I make that it would randomaly pick number from like 500 to 1000 ? If I do random(1000) it will pick from 0 to 1000...
Reply
#2

You want a minimum of 500 and a max of 1000. The difference between the numbers is 500 so do:

pawn Код:
random ( 500 ) + 500;
or use

pawn Код:
stock RandomMinMax ( min , max )
{
  return random ( max - min ) + min;
}
Reply
#3

Quote:
Originally Posted by WrathOfGenesis
pawn Код:
stock RandomMinMax ( min , max )
{
  return random ( max - min ) + min;
}
pawn Код:
stock RandomMinMax ( min , max ) return random ( max - min +1 ) + min;
Reply
#4

Thanks
Reply
#5

Why + 1?

That means if the lowest value is 0 and the highest is 5 it can return 6.
Reply
#6

The random(max) function chooses a number between 0 and max-1 (from Pawn_Language_Guide.pdf)
Reply
#7

Checked my randomminmax function in my script and your right. My mistake
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)