?
Solved

PHP random number, not starting with zero

Posted on 2009-05-08
3
Medium Priority
?
303 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 1000 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 1000 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

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

771 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