Search results
Results from the WOW.Com Content Network
Yes, though if you're choosing just one letter that doesn't make a difference Furthermore, you may want 5 unique letters - the OP didn't specify, and both random.choice and random.randint return a single value.
First, as others have mentioned, it has a small probability of producing short strings or even an empty string (if the random number is 0), which may break your application. Here is a solution: (Math.random().toString(36)+'00000000000000000').slice(2, N+2) Second, both the original and the solution above limit the string size N to 16 characters.
Do note that java.util.Random is actually a pseudo-random number generator based on the rather weak linear congruence formula. You mentioned the need for cryptography; you may want to investigate the use of a much stronger cryptographically secure pseudorandom number generator in that case (e.g. java.security.SecureRandom).
In particularly, secrets should be used in preference to the default pseudo-random number generator in the random module, which is designed for modelling and simulation, not security or cryptography. In testing generation of 768bit security tokens I found: random.choices() - 0.000246 secs; secrets.choice() - 0.003529 secs
(Note: The use of the Random class makes this unsuitable for anything security related, such as creating passwords or tokens. Use the RNGCryptoServiceProvider class if you need a strong random number generator.)
I put together a PHP class for generating random numbers and strings PHPRandomValue, It uses "mcrypt_create_iv(4, MCRYPT_DEV_URANDOM)" to generate random numbers and values. I made it while working on a crypto project because I needed a safe random value generator and mt_rand() doesn't meet that requirement. Here's an example usage
rem // generate a random number between 65 and 90 set /a "ascii = %random% * 26 / 32768 + 65" rem // set errorlevel to that number cmd /c exit /b %ascii% rem // get letter corresponding to that exit code echo %=ExitCodeAscii%
The maximum length is 11 and, depending on the random number generated, sometimes you get 10 characters instead. – Tom Fenech Commented Apr 21, 2014 at 13:16
I want to make a random character generator with numbers in vb.net, I know how to make a random number generator but not numbers mixed with letters. I want it to be around 15-20 characters. Something like this: F53Gsfdsj637jfsj5kd8. Thanks ahead!
In particularly, secrets should be used in preference to the default pseudo-random number generator in the random module, which is designed for modelling and simulation, not security or cryptography. Looking more into what it has to offer I found a very handy function if you want to mimic an ID like Google Drive IDs: