Random numeric strings
#20

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
a) Use valstr for strings consisting purely of a number.

b) marrcko's code was the closest, but still not quite right for the same reason "random(9)" wasn't quite right:

pawn Код:
new
    str[7]
valstr(str, random(900000) + 100000);
That will generate a random number in the interval [0,899999], previous code did [0,899999), then add 100000 to give [100000,999999] (i.e. all the 6-digit numbers). Note that this excludes numbers like 000001, if you want those too:

pawn Код:
new
    str[7]
format(str, sizeof (str), "%06d", random(1000000));
In this case "format" is the better option as you're using more advanced features.
Thanks for the response, Alex.
Reply


Messages In This Thread
Random numeric strings - by Scenario - 18.08.2011, 01:39
Re: Random numeric strings - by JaTochNietDan - 18.08.2011, 02:00
Re: Random numeric strings - by Scenario - 18.08.2011, 02:02
Re: Random numeric strings - by =WoR=Varth - 18.08.2011, 02:09
Re: Random numeric strings - by Scenario - 18.08.2011, 03:09
Re: Random numeric strings - by =WoR=Varth - 18.08.2011, 03:32
Re: Random numeric strings - by Scenario - 18.08.2011, 03:34
Re: Random numeric strings - by =WoR=Varth - 18.08.2011, 03:40
Re: Random numeric strings - by Scenario - 18.08.2011, 03:44
Re: Random numeric strings - by DRIFT_HUNTER - 18.08.2011, 03:45
Re: Random numeric strings - by =WoR=Varth - 18.08.2011, 03:52
Re: Random numeric strings - by Scenario - 18.08.2011, 04:18
Re: Random numeric strings - by PrawkC - 18.08.2011, 04:19
Re: Random numeric strings - by Scenario - 18.08.2011, 04:22
Re: Random numeric strings - by PrawkC - 18.08.2011, 04:23
Re: Random numeric strings - by Scenario - 18.08.2011, 04:44
Re: Random numeric strings - by iggy1 - 18.08.2011, 06:16
Re: Random numeric strings - by marrcko - 18.08.2011, 08:05
Re: Random numeric strings - by TouR - 18.08.2011, 08:16
Re: Random numeric strings - by Scenario - 18.08.2011, 18:32

Forum Jump:


Users browsing this thread: 1 Guest(s)