salt.modules.mod_random

Provides access to randomness generators.

New in version 2014.7.0.

salt.modules.mod_random.get_str(length=20)

New in version 2014.7.0.

Returns a random string of the specified length.

length20

Any valid number of bytes.

CLI Example:

salt '*' random.get_str 128
salt.modules.mod_random.hash(value, algorithm='sha512')

New in version 2014.7.0.

Encodes a value with the specified encoder.

value

The value to be hashed.

algorithmsha512

The algorithm to use. May be any valid algorithm supported by hashlib.

CLI Example:

salt '*' random.hash 'I am a string' md5
salt.modules.mod_random.rand_int(start=1, end=10, seed=None)

Returns a random integer number between the start and end number.

start1

Any valid integer number

end10

Any valid integer number

seed :

Optional hashable object

Changed in version 2019.2.0: Added seed argument. Will return the same result when run with the same seed.

CLI Example:

salt '*' random.rand_int 1 10
salt.modules.mod_random.seed(range=10, hash=None)

Returns a random number within a range. Optional hash argument can be any hashable object. If hash is omitted or None, the id of the minion is used.

hash: None

Any hashable object.

range: 10

Any valid integer number

CLI Example:

salt '*' random.seed 10 hash=None
salt.modules.mod_random.shadow_hash(crypt_salt=None, password=None, algorithm='sha512')

Generates a salted hash suitable for /etc/shadow.

crypt_saltNone

Salt to be used in the generation of the hash. If one is not provided, a random salt will be generated.

passwordNone

Value to be salted and hashed. If one is not provided, a random password will be generated.

algorithmsha512

Hash algorithm to use.

CLI Example:

salt '*' random.shadow_hash 'My5alT' 'MyP@asswd' md5
salt.modules.mod_random.str_encode(value, encoder='base64')

New in version 2014.7.0.

value

The value to be encoded.

encoderbase64

The encoder to use on the subsequent string.

CLI Example:

salt '*' random.str_encode 'I am a new string' base64