Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

String::Random

by ishmael (Novice)
on Jun 13, 2001 at 12:08 UTC ( [id://88021]=modulereview: print w/replies, xml ) Need Help??

Item Description: Generate random strings based on a pattern

Review Synopsis:

Motivation

Until I saw this module, String::Random I have been using clunky ways to generate random text, always having to lookup ascii codes. This module is an excellent way to generate random strings from a template of possible characters.

Instant Random Strings

use String::Random; $foo = new String::Random; # e.g. AqF8, YcE2, BjW8 ... $string = $foo->randpattern("CcCn");

yields a random four character string: uppercase letter, lowercase, uppercase and then a number. Need a license plate? randpattern("CnCnCn") works for where I live

Smarter Random Strings

Particularly useful is the ability to define sets of characters and assign them to a pattern

# define vowels $foo->{'V'} = [ qw(a e i o u) ]; # define common consonants $foo->{'Q'} = [ qw(r s t n m) ]; # e.g. retom, satan, timis ... $string = $foo->randpattern("QVQVQ");

particularly useful for generating names of MUD characters.

Random Regex

The module also accepts a regex as input.

# e.g. 342, 289, 832 ... print $foo->randregex('\d\d\d');

My Own Usage

  • generate short random sequences of DNA using $foo->{'V'} = [ qw(a t g c) ]; to define the four base pairs
  • generate passwords for users that are relatively easy to remember, like $foo->randpattern("!QVCVQn") which gives .saZem9 +nicot8 and so on
  • random file names without all the randomness of using Digest::MD5

This is one of those small-tool modules that you may find yourself using over and over again.

Edit: chipmunk 2001-06-18

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: modulereview [id://88021]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2025-02-11 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found