Generate random strings in multiple ways in Javascript.
Use crypto
The quickest and easiest way to generate random strings.
|
|
Crypto library is available in node. On the client side, use window.crypto
.
Use random
Use Math.random()
to generate a string of random set of characters and numbers.
|
|
The above code converts a random number to to its base-36 form (toString(36)
) and outputs the string after removing the prefix.
Use faker
Faker libraries (here’s a popular one) help you not only to generate random strings, but random anything.
You can locally install the library and start cranking up randoms.
|
|
Other
-
Use the hosted service for faker libraries. Note that these are hosted on servers that do not support large number of concurrent connections and may throw errors.
1 2
curl http://faker.hook.io?property=name.findName
- If you are looking at generating data quickly and do not care about reuse, you can look at online generators like [https://www.generatedata.com/]