A little password generator I lazily threw together for some tables practice.
Feel free to use it for actual passwords!
(It's literally just a string of random numbers and letters)
Special thanks to kittenm4ster for helping me fix something in the code, making the generator consistent! :)
There's no point in calling srand() with a rnd() value; that will not give you any additional entropy.
Also, the PRNG is automatically seeded every time you start running a cart, so there's not really a reason to even call srand() unless you are trying to reproduce the same sequence in the PRNG for debugging purposes or whatever.
You probably already know this, but the other thing to note is that the PRNG in PICO-8 is almost certainly (unless zep really went above and beyond!) not cryptographically secure and not intended for use in security applications. Security and gamedev have very different requirements for randomness; in gamedev you can get away with using a pretty low-entropy PRNG and still get great results :)
As for why you don't get the same number of characters every time, just from a cursory reading of the code, it looks to me like you are generating a random number from 0-34 (inclusive) and then if that number is > 9 then you are using it as an index into your table of letters, so you are only ever starting at the 10th letter in your table, and sometimes, going past the end of the table (when the number is > 26) which results in no letter being returned from the table lookup.
Log in to post a comment