Solved

PHP random number, not starting with zero

Posted on 2009-05-08
3
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24333781
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
ID: 24333830
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
ID: 24333874
I was thinking way to complex. Thanks guys
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
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.

691 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