How to do it? [ADVANCE] - 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: How to do it? [ADVANCE] (
/showthread.php?tid=319742)
How to do it? [ADVANCE] -
Not Applicable - 20.02.2012
How to get an unique randomize number of a predefined length?
Re: How to do it? [ADVANCE] -
Babul - 20.02.2012
the number "123456789" is 9 in lenght, so 10^9 in size as basis. you can do:
pawn Код:
100000000+random(900000000)
which gives any number ranging from 100000000 to 999999999. do this with 10^0:
1+random(9) equals 1,2,3,4,5,6,7,8,9, and
10+random(90) equals 10 to 99...
Re: How to do it? [ADVANCE] -
Not Applicable - 20.02.2012
Quote:
Originally Posted by Babul
the number "123456789" is 9 in lenght, so 10^9 in size as basis. you can do:
pawn Код:
100000000+random(900000000)
which gives any number ranging from 100000000 to 999999999. do this with 10^0:
1+random(9) equals 1,2,3,4,5,6,7,8,9, and
10+random(90) equals 10 to 99...
|
thanks and one more question. How to generate the number until and unless it's unique?
Re: How to do it? [ADVANCE] -
Deduction - 20.02.2012
You would probably need to have it save numbers to a file, saving the last number used, then loading the next number.
Re: How to do it? [ADVANCE] -
Not Applicable - 20.02.2012
Quote:
Originally Posted by Deduction
You would probably need to have it save numbers to a file, saving the last number used, then loading the next number.
|
I know, but how to do it on while loop. Cause there maybe more than 1 number on the file the random number generated.