by LAI (Hermit)
 on Jun 13, 2004 at 10:23 UTC 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";
}

Create A New User
Chatterbox?
 [virtualsue]: 1nickt thatch repair just finishing [virtualsue]: they've done enough to get it through winter holli loves lightning talks [1nickt]: ... but not the last straw? 1nickt ducks

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2017-11-21 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In order to be able to say "I know Perl", you must have:

Results (299 votes). Check out past polls.

Notices?