Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

LAI's scratchpad

by LAI (Hermit)
on Jun 13, 2004 at 10:23 UTC ( #363783=scratchpad: print w/replies, xml ) Need Help??

To be translated to Perl and golfed:

head -c 200 /dev/urandom | perl -e '$i=0;foreach (split //, <>) {s/[\s +\W]//g;print}#$i++,$_,$/}' | head -c 8; echo

Some more code for Ella...

Here's an example of how to generate as many random numbers as you like with the rand() function. Let's assume you want to generate 1000 integers between 666 and 1337 inclusive. You'll want to do something with each obviously, so I'll just print them out. Here goes:

#!/usr/bin/perl use strict; use warnings; # a basic script to generate some (pseudo)random numbers and # print them out. # our parameters: my $count = 1000; # how many numbers do we want my $lbound = 666; # lower bound (inclusive) of our range my $ubound = 1337; # upper bound (inclusive) of our range # what follows is shorthand: We execute what's between the # {braces} until what's in the (parentheses) evaluates to # false. In the parens, we post-decrement $count, which # returns the value of $count before the incrementing. This # way, the first time through $count becomes 999 and the # expression evaluates to 1000. The second time $count # becomes 998 and the expression evaluates to 999, and so # on. We also have the pre-decrement: (++$count). This is # identical to the post-decrement, except that the value # returned is $count after being decremented. while ($count--) { # The next line generates our random number. The rand() # function generates a real number greater than or equal # to zero, and less than the number you pass it. The # int() function truncates fractional numbers and returns # the integer part. So we give rand() a range that will # be the right size -- in this case 0 to 671 -- and then # add 666 to it to get a range from 666 to 1337. my $rannum = int rand($ubound - $lbound + 1) + $lbound; # Now do whatever you like with the number. print "$rannum is my favourite number! \n"; }

Ask and ye shall receive.

Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-06-28 21:21 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (648 votes). Check out past polls.