How to make it random
#1

Hey i'm creating a agent card.

I want to make it random numbers, how to make it in random numbers?

like

Код:
AgentCard = 00912842315
Agent Card is a integer not a string.
Reply
#2

pawn Код:
new AgentCard = random(800000);//the highest random number
Reply
#3

Is there limit number in random?
Cause i wanna make it random up to 11 length numbers so it will be really look like a cellphone number (look a like but it works different)
Reply
#4

don't think so as i use it to randomize X,Y,Z positions which are pretty long.
But if you want to keep it short you can random two numbers and add them together
Reply
#5

There is, it's 2,147,483,647 which is the maximum 32-bit integer in PAWN (signed).

If you want an 11 length number:

pawn Код:
new rand1 = random(500000 - 100000) + 100000;
new rand2 = random(50000 - 10000) + 10000;

new string[64];
format(string, sizeof(string), "%d%d", rand1, rand2);
Reply
#6

thanks both of you..
Reply
#7

You can set random numbers to a string (because a 32-bit cell has limitations in it's capacity to hold a very large number)

pawn Код:
stock SetRandomNumber(string[], size = sizeof string)
{
    for(new i; i < size; i++) string[i] = 48 + random(10);
    return string;
}

//Usage:

public OnFilterScriptInit()
{

    new MyString[16]; //<-- array size is the number of digits
    SetRandomNumber(MyString);
    printf("%s", MyString);
   
    return 1;
}
Reply
#8

PHP код:
new filestring[128];
format(filestringsizeof(filestring), "scriptfiles/Administration/Users/%s.ini"pname);
new 
arand =random(2,147,483,647);
new 
INI:File INI_Open(filestring);
INI_SetTag(File,"Player's Data");
INI_WriteInt(File"Agent Numer",arand);
INI_Close(File); 
For Y_INI
Reply
#9

Why don't you change it to string?

INI_WriteString(...);
Reply
#10

^^

I already did it change to string, i use Emmet_'s code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)