To use the functions below, make sure you have the following import at the top of your problem code:

loadMacros("randomizers.pl");

# Random numbers

random($min, $max)

Returns a random number between $min and $max (inclusive), with step size 1.

Sample usage:

$x = random(5, 10); # assigns $x to be a random number between 5 and 10 inclusive, with step size 1.

random($min, $max, $step)

Returns a random number between $min and $max (inclusive), with step size $step.

Sample usage:

$x = random(5, 10, .25); # assigns $x to be a random number between 5 and 10 inclusive, with step size .25

rands($min, $max, $n)

Returns $n values from $min to $max with a step size of 1

Sample usage:

@randvals = rands(2, 10, 4); # @randvals will contain 4 random values from 2 to 10

rrands($min, $max, $step, $n)

Returns $n values from $min to $max with a step size of $step

Sample usage:

@randvals = rrands(2, 10, .25, 4); # @randvals will contain 4 random values from 2 to 10 with a step size of .25

diffrands($min, $max, $n)

Returns $n different values from $min to $max with a step size of 1

Sample usage:

@randvals = diffrrands(2, 10, 4); # @randvals will contain 4 different random values from 2 to 10

diffrrands($min, $max, $step, $n)

Returns $n different values from $min to $max with a step size of $step

Sample usage:

@randvals = diffrrands(2, 10, .25, 4); # @randvals will contain 4 different random values from 2 to 10 with a step size of .25

# Random elements of lists

randfrom(@list)

Returns a randomly selected element from @list

Sample usage:

@list = (3, 5, 7, 9);

$element = randfrom(@list) # $element will be a randomly selected element from @list

randsfrom(@list, $n)

Returns $n different values from @list

Sample usage:

@list = (3, 5, 7, 9);

@sublist = randsfrom(@list, 2) # @sublist will contain two different, randomly selected elements from @list

# Random places

randcountry()

Returns a randomly selected country

Sample usage:

$country = randcountry();

randcountries($n)

Returns $n randomly selected countries

Sample usage:

@countries = randcountries(10);

randcity()

Returns a randomly selected US city

Sample usage:

$city = randcity();

randcities($n)

Returns $n randomly selected US cities

Sample usage:

@cities = randcities(10);

randstate()

Returns a randomly selected US state

Sample usage:

$state = randstate();

randstates($n)

Returns $n randomly selected US states

Sample usage:

@states = randstates(10);

# Random names

randname()

Returns a randomly selected first name

Sample usage:

$name = randname();

randnames($n)

Returns $n randomly selected first names

Sample usage:

@names = randnames(10);