Since each of your variables depends of the result of an operation on an other, and since time doesn't do much (because the value of localtime only changes every second as expressed by Athanasius), and since you reset srand each time you call your function, I would be surprised if you didn't end with a loop very fast. Because if you get the same randseed twice, rand will give you the same numbers, and so you'll go through exactly the same list of numbers until the value of localtime changes.

That's what you get for calling srand with the ouput of rand:

eval { $n = int rand(20); srand $n; print $n.' ' } for (1..10)
13 9 0 3 15 4 13 9 0 3

You just put additional layers to that problem, and a restart every second.

As for your toASCII sub, have a look at pack, unpack, and the perlpacktut.

My advice: if you want to make your own RNG: do go on. But do it from scratch, do not use rand, because that's actually what does all the work in your programs, and it prevents you to see the flaws in what you do. If you try and make your own RNG, and use it for a large scale number generation, you'll learn far more than trying to improve something that's possibly better than whatever you may achieve.


In reply to Re: random question by Eily
in thread random question by perlaintdead

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.