Skip to content

Easy Random

py_simple.easy_random

easy_random is built to simplify common random choices, numbers, and shuffling.

flip_coin()

Simulates a coin toss, returning 'Heads' or 'Tails'.

Returns:

Name Type Description
str str

'Heads' or 'Tails'.

Example
from py_simple import flip_coin

result = flip_coin()  # -> 'Heads'
import random

result = random.choice(["Heads", "Tails"])

pick_random_item(items)

Picks a single random element from a list or tuple.

Parameters:

Name Type Description Default
items Sequence[Any]

The collection to pick from.

required

Returns:

Name Type Description
Any Any

A randomly chosen element from the sequence.

Example
from py_simple import pick_random_item

fruit = pick_random_item(["apple", "banana", "cherry"])  # -> 'banana'
import random

fruit = random.choice(["apple", "banana", "cherry"])

random_int(start, end)

Generates a random integer between start and end (inclusive).

Parameters:

Name Type Description Default
start int

The lower bound.

required
end int

The upper bound.

required

Returns:

Name Type Description
int int

A random integer within [start, end].

Example
from py_simple import random_int

num = random_int(10, 20)  # -> e.g. 17
import random

num = random.randint(10, 20)

roll_dice(sides=6)

Simulates rolling a die with a given number of sides (default is 6).

Parameters:

Name Type Description Default
sides int

Number of sides on the die. Defaults to 6.

6

Returns:

Name Type Description
int int

A random integer between 1 and sides inclusive.

Example
from py_simple import roll_dice

result = roll_dice(6)  # -> e.g. 4
import random

result = random.randint(1, 6)

shuffle_list(items)

Returns a new list with the items shuffled in random order.

Parameters:

Name Type Description Default
items Sequence[Any]

The items to shuffle.

required

Returns:

Type Description
List[Any]

List[Any]: A new shuffled copy of the list.

Example
from py_simple import shuffle_list

shuffled = shuffle_list([1, 2, 3, 4, 5])  # -> e.g. [3, 1, 5, 2, 4]
import random

my_list = [1, 2, 3, 4, 5]
shuffled = list(my_list)
random.shuffle(shuffled)