How to get a random character from a range in JavaScript?
You can do this :
String.fromCharCode(0x30A0 + Math.random() * (0x30FF-0x30A0+1));
Note that 0x30FF-0x30A0
is 95
, and if you want the last one you must add 1
(Math.random
returns a result in [0,1[
), which makes 96
, not 60
.
You can do this:
String.fromCharCode(Math.floor(Math.random() * 65535));
Because maximum hex is 65536.
Maximum hex: 16 ^ 4