Solved

Php - random with 4 digits

Posted on 2012-09-04
Medium Priority
513 Views
Hi E's, can you show me how I do a random with four digits [0-3]?
md5 can do that?

The best regards, JC
0
Question by:Pedro Chagas
• 3
• 2

LVL 75

Accepted Solution

käµfm³d   👽 earned 640 total points
ID: 38363380
Why not just use the rand function?

e.g.

``````\$random = rand(1000, 9999);
``````
0

LVL 35

Expert Comment

ID: 38363455
Try this:
``````<?php

// Generate a random number

// Generate a random password and append the random number

{
\$randChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#\$%^&*()_+-=.,?";
for(\$i = 0; \$i < 16; \$i++)
{
}
}
?>
``````
0

LVL 3

Author Closing Comment

ID: 38364989
Hi @gr8gonzo, you read my question?
Thanks for both.

The best regards, JC
0

LVL 35

Expert Comment

ID: 38365221
Hi JC,

Yes, I did. You said "random WITH four digits". When you say "with", it sounds like you're saying "a random" AND "four digits".  I assumed you meant "a random string" + 4 digits. That is what my code provides.
0

LVL 3

Author Comment

ID: 38365284
My apologizes. English language is not my native language. I try write the best I can.
The best regards, JC
0

LVL 35

Expert Comment

ID: 38365365
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses
Course of the Month15 days, 16 hours left to enroll