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


In reply to Re^5: making random number by davido
in thread making random number by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.