Skip to content

Basic

This is a basic module, it contains integer, float, string, boolean, and date types.

Boolean

dunna.basic.boolean() returns a random boolean value.

// Use default likelihood = 50
dunna.basic.boolean(); // true
dunna.basic.boolean(); // false
dunna.basic.boolean(); // false
// Modify likelihood
dunna.basic.boolean({ likelihood: 80 }); // The output has chance of 80% to be true
dunna.basic.boolean({ likelihood: 20 }); // The output has chance of 20% to be true
ParameterTypeDescriptionDefault
likelihoodnumberThe likelihood of the output being true50

Integer

dunna.basic.integer() returns a random integer between 0 (not inclusive) and 10 (inclusive)

dunna.basic.integer(); // 4
dunna.basic.integer(); // 7
dunna.basic.integer(); // 4
// Customize parameters
dunna.integer({ min: 1, max: 100 });
dunna.integer({ min: -10, max: 10 });
ParameterTypeDescriptionDefault
minnumberThe minimum value of the output (inclusive)0
maxnumberThe maximum value of the output (not inclusive)10

Float

dunna.basic.float() returns a random float number between 0 (inclusive) and 10 (not inclusive)

dunna.basic.float(); // 4.364
dunna.basic.float(); // 8.834
// Parameters
dunna.float({ min: 3, max: 36, fixed: 5 });
ParameterTypeDescriptionDefault
minnumberThe minimum value of the output (inclusive)0
maxnumberThe maximum value of the output (not inclusive)10
fixednumberThe number of decimal places3

Letter

dunna.basic.letter() returns a random uppercase or lowercase letter

dunna.basic.letter(); // h
dunna.basic.letter(); // E
// Parameters
dunna.basic.letter({ casing: "upper" });
ParameterTypeDescriptionDefault
casingstringThe casing of the output letter (upper/lower/any)“any”

Choice

dunna.basic.choice(array) returns a random element from an array

dunna.basic.choice(["Alice", "Bob", "Charlie"]); // Alice
dunna.basic.choice(["Alice", "Bob", "Charlie"]); // Charlie
ParameterTypeDescriptionDefault
arrayT[]The array to be randomly selectednull

Pick

dunna.basic.pick(count, array) returns a random subset of the given array with the given count

dunna.basic.pick(3, [2, 1, 6, 3, 4]); // [6, 4, 1]
dunna.basic.pick(2, ["Alice", "Bob", "Charlie"]); // ['Bob', 'Charlie']
ParameterTypeDescriptionDefault
countnumberThe number of elements to be pickednull
arrayT[]The array to be randomly selectednull

Omit

dunna.basic.omit(count, array) returns a random subset of the given array by omitting elements based on the given count

dunna.basic.omit(2, [2, 1, 6, 3, 4]); // [1, 6 ,4]
dunna.basic.omit(2, ["Alice", "Bob", "Charlie"]); // ['Bob']
ParameterTypeDescriptionDefault
countnumberThe number of elements to be omittednull
arrayT[]The array to be randomly selectednull