Oct 31, 2013

Random Numbers or Password or Pin in MySQL

To obtain a random integer R in the range i <= R < j, use the expression FLOOR(i + RAND() * (j – i)). For example, to obtain a random integer in the range the range 7 <= R < 12, you could use the following statement:
SELECT FLOOR(7 + (RAND() * 5));

To generate between 1000 to 9999, i.e., 4 digits then you can do the following using update query
 UPDATE users SET password = FLOOR(1000 + RAND() * 8999);

No comments:

Post a Comment

Want to tell something about this post. Please feel free to write...