Solved

PHP random number, not starting with zero

Posted on 2009-05-08
3
267 Views
Last Modified: 2012-05-06
Hellow all,

I need to create a random number of 10 digits (member id). But the number must not start with a zero.

How can this be done.

greetz,
walter
0
Comment
Question by:wal_toor
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
logic:
create a random number between 0 and 8999999999   and then simply add 1000000000 to it
0
 
LVL 14

Assisted Solution

by:shobinsun
shobinsun earned 250 total points
Comment Utility
Hi.,

The random number generated is a 32bit integer. That limits it to 9 digits maximum. Of course you could just stick two 5 digit randoms together. They are random after all...

echo mt_rand(10000,99999) . mt_rand(10000,99999) ;
0
 
LVL 8

Author Comment

by:wal_toor
Comment Utility
I was thinking way to complex. Thanks guys
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
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 dynamically set the form action using jQuery.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now