18.08.2011, 01:39
I need a way to generate random strings consisting of numeric characters only. I searched and went through over 10 pages but couldn't find anything. Can anyone assist me?
format(string,sizeof(string),"%d",random(9999));
format(string,sizeof(string),"%d%d%d%d",random(9),random(9),random(9),random(9));
valstr(string,random(9999));
Another.
pawn Code:
|
stock randNumber()
{
new szString[13];
format(szString, sizeof(szString), "%d%d%d%d%d%d", random(9), random(9), random(9), random(9), random(9), random(9));
return szString;
}
Sorry to say, but you're wrong.
Give the wiki a read https://sampwiki.blast.hk/wiki/Random "Returns A random number ranging from 0 to max-1." |
#define RandomEx(%1,%2) (random(%2-%1)+%1)// RandomEx(min, max)
public OnFilterScriptInit()
{
new
szStr[11];
format(szStr, sizeof(szStr), "%i", RandomEx(1000, 9999));
print(szStr);
return 1;
}
format(string,sizeof(string),"%d",100000+random(899999));
szString = random(99999)+100000;
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 Код:
pawn Код:
|