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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-23 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found