• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Random letters and numbers
#4
When printing a single character (which is just a number), use %c (which stands for character, obviously). %s is for strings (arrays).
Also be more specific. "It doesn't work". What doesn't work? Does it print weird characters? (Which is likely since you used specificer s instead of c). Or does it not work at all? If so, there is another problem going on.

Quote:random('0'-'9')
https://open.mp/docs/scripting/functions/random
random() takes as parameter "max", not a "range". For example, if the input is 15 it will return a random value from 0 up to 14. Negative values (0-9 = -9) will print large values.
When wrapping something in single quotes (eg. 'a', '9') it will return the numeric value of that character. For example, '5' is 5, but 'a' has numeric value 97. So when using:
Code:
'A'  random('Z' - 'A'  1)
You're actually doing:
Code:
65  random(90 - 65  1) //65  random(26): Output will be 65  (0-25), so output will be atleast 65 ('A') and maximal 65(90) ('Z')
Note that these character numbers are ASCII numbers (if I'm not wrong): http://www.asciitable.com/ (I believe SAMP covers 128 of them?)
Quote:Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort
  Reply


Messages In This Thread
Random letters and numbers - by Frajola - 2020-11-25, 10:18 PM
RE: Random letters and numbers - by Freaksken - 2020-11-25, 11:20 PM
RE: Random letters and numbers - by Frajola - 2020-11-26, 01:01 AM
RE: Random letters and numbers - by Kwarde - 2020-11-26, 02:27 AM
RE: Random letters and numbers - by Frajola - 2020-11-26, 03:40 AM

Forum Jump: