SA-MP Forums Archive
Random number - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Random number (/showthread.php?tid=571290)



Random number - Mrki_Drakula - 17.04.2015

Hello,

Can anyone help me with pointing out how can i add a code that gets random 10 digit number but with same 3 digits first...like:

1625060504
1621306123
1626023010

Thanks!


Re: Random number - Konstantinos - 17.04.2015

pawn Код:
format(string, sizeof (string), "162%i%i%i%i%i%i%i", random(10), random(10), random(10), random(10), random(10), random(10), random(10));



Re: Random number - Jimmy0wns - 17.04.2015

Function
PHP код:
stock randomEx(minmax)
{    
    
//Credits to ******    
    
new rand random(max-min)+min;    
    return 
rand;

Usage
PHP код:
RandomEx(16200000001630000000); 
My method seems to be better but correct me if I'm wrong.


Re: Random number - Mrki_Drakula - 17.04.2015

Thank you both!

Would this work?

Код:
new phonenumber = RandomEx(1620000000, 1630000000);		
PlayerInfo[playerid][pnumber] = phonenumber;
Код:
stock randomEx(min, max)
{
    //Credits to ******
    new rand = random(max-min)+min;
    return rand;
}



Re: Random number - Jimmy0wns - 17.04.2015

Quote:
Originally Posted by Mrki_Drakula
Посмотреть сообщение
Thank you both!

Would this work?

Код:
new phonenumber = RandomEx(1620000000, 1630000000);		
PlayerInfo[playerid][pnumber] = phonenumber;
Код:
stock randomEx(min, max)
{
    //Credits to ******
    new rand = random(max-min)+min;
    return rand;
}
That should work, unless your [pnumber] is a float.


Re: Random number - Mrki_Drakula - 17.04.2015

Its says undefined randomEx even when i put the stock...


Re: Random number - Azula - 17.04.2015

follow Konstantinos method it's more easy


Re: Random number - Jimmy0wns - 17.04.2015

Quote:
Originally Posted by Azula
Посмотреть сообщение
follow Konstantinos method it's more easy
It's a hard way of doing it while it could be done easier.

Quote:
Originally Posted by Mrki_Drakula
Посмотреть сообщение
Its says undefined randomEx even when i put the stock...

also it says undefined phonenumber
Are you sure you used it correctly?

Here's an example:
PHP код:
stock randomEx(minmax)
{    
    
//Credits to ******    
    
new rand random(max-min)+min;    
    return 
rand;
}
CMD:randomnumber(playeridparams[])
{
    new 
value RandomEx(16200000001630000000);
    
printf("the value is %d"value);
    return 
1;




Re: Random number - Mrki_Drakula - 17.04.2015

C:\Users\Crysis\Desktop\MusaBM.pwn(49709) : error 017: undefined symbol "RandomEx"

PHP код:
new brojtelefona RandomEx(16200000001630000000);
PlayerInfo[playerid][pnumber] = brojtelefona
and somewhere at the start

PHP код:
stock randomEx(minmax)
{
    
//Credits to ******
    
new rand random(max-min)+min;
    return 
rand;

EDIT: Wow wait i copied your code and havent seen the mistype


Re: Random number - Jimmy0wns - 17.04.2015

Quote:
Originally Posted by Mrki_Drakula
Посмотреть сообщение
C:\Users\Crysis\Desktop\MusaBM.pwn(49709) : error 017: undefined symbol "RandomEx"

PHP код:
new brojtelefona RandomEx(16200000001630000000);
PlayerInfo[playerid][pnumber] = brojtelefona
and somewhere at the start

PHP код:
stock randomEx(minmax)
{
    
//Credits to ******
    
new rand random(max-min)+min;
    return 
rand;

It's randomEx, not RandomEx.
It might be useful to read the function name first.