Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^5: making random number

by davido (Cardinal)
on Aug 25, 2014 at 16:22 UTC ( [id://1098533]=note: print w/replies, xml ) Need Help??


in reply to Re^4: making random number
in thread making random number

I wouldn't expect that to work. You needed an 8-digit random number with 912 prepended to it. Your code will produce a 2-digit random number, and then line 3 won't even compile. Even if it did compile, it would fail to produce an 8-digit (with three or four digits prepended) anytime the random number has leading zeros. That's why I used 'sprintf'.

CountZero was correct that just adding 91200000000 to any eight digit (or less) random number will give you the correct number of digits. But now you seem to be putting a zero at the beginning too, so in that case you probably need a string-based approach, which is what sprintf will do for you.

Are you generating phone numbers within an area code? Is it really seven-digits you're after? :)

Where are the text book, professor, teacher's aid, and other classmates through this process? This assignment certainly didn't appear without prior explanation. You may find the learning process, at your early stage, to be more productive if you could spend 10 minutes face to face with an instructor or teacher's aid.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1098533]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-19 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found