Random password generation

Hi All,

How to create password randomly without using predefined functions ?
Example, without using substr , rand , …

Anyone plz help…

Without microtime, md5 ?

I don’t know.
Why don’t you want to use php functions?

Actually this is my interview question . That time i dont know . So only Posted this thread…

without that also


$password = "7"; // randomly chosen password

As worded, your question is asking “How do I write PHP without using PHP?”. Obviously, that’s not possible.

It is, you just have to write the functions yourself, create the required algorithms using PHP’s constructs (if for while, etc). Not very practical, however. These types of question in interviews are used to determine if you know PHP at a deeper level.

The most difficult part would be writing your own random number generator. Once you have that then you can simply create a string of characters that are to be selected from for the password and then use a loop that generates random numbers and then pulls the corresponding character out of the string and adds it to the password.

thank you for all reply…

That wouldn’t really show that you knew PHP any deeper. It would really only show that you knew how random numbers were generated.

That would depend on whether they actually required that you write the code or just describe how you’d approach that problem. If you were required to write the code then it would show that you know how to generate pseudo random numbers. If you are just required to describe how you’d approach it then it tells them something of your understanding of programming logic (although not specifically related to PHP).

You are right that it doesn’t demonstrate any deeper knowledge of PHP but then that might not be the purpose of the question.

I think that in an interview context, the answer to this question is that you would have to write your own equivalent random number generator… in essence, this is the core of any password generator.

However, any function you could write would not be as efficient as PHPs built in functions and therefore should not be used…

Fair enough, though I wasn’t sure upon the original reading whether built in functions included language constructs.

Is it telling that my response to the question would be “I wouldn’t”? Proprietary random number generators are nearly always poorly written, and should be avoided like the plague.

I wonder if that would’ve been an acceptable answer.