Skip to content

Basic

Primitives and small utilities: booleans, integers, floats, letters, and random picks from arrays.

boolean

Returns a random boolean. Optionally bias the probability of true.

ts
dunna.basic.boolean();
dunna.basic.boolean({ probability: 0.8 });
OptionTypeDescriptionDefault
probabilitynumberChance that the result is true, between 0 and 10.5

Throws if probability is outside [0, 1].

integer

Returns a random integer in the half-open range [min, max) — the maximum is exclusive, matching internal float sampling and Math.floor.

ts
dunna.basic.integer(); // e.g. 0–9 with defaults below
dunna.basic.integer({ min: 1, max: 100 });
OptionTypeDescriptionDefault
minnumberLower bound (inclusive), must be an integer0
maxnumberUpper bound (exclusive), must be an integer10

Throws if min or max are not integers.

float

Returns a random floating-point number in [min, max) (maximum exclusive), rounded to a limited number of decimal places.

ts
dunna.basic.float();
dunna.basic.float({ min: 3, max: 36, fixed: 5 });
OptionTypeDescriptionDefault
minnumberLower bound (inclusive)0
maxnumberUpper bound (exclusive)10
fixednumberDecimal places kept3

letter

Returns a single random letter from the Latin alphabet.

ts
dunna.basic.letter();
dunna.basic.letter({ casing: 'upper' });
OptionTypeDescriptionDefault
casing'upper' | 'lower' | 'any'Letter case'any'

pickOne

Returns one random element from a non-empty array.

ts
dunna.basic.pickOne(['Alice', 'Bob', 'Charlie']);
ArgumentTypeDescription
choicesT[]Array to draw from

pickMany

Returns distinct random elements: count items sampled without replacement. Order is not guaranteed.

ts
dunna.basic.pickMany(3, [2, 1, 6, 3, 4]);
ArgumentTypeDescription
countnumberHow many items to pick (integer, 0array.length)
arrayT[]Source array

Throws if count is out of range or not an integer. If count equals array.length, returns a permutation of the array.

omit

Returns array.length - count elements: the complement of pickMany for a fixed omit size.

ts
dunna.basic.omit(2, [2, 1, 6, 3, 4]);
ArgumentTypeDescription
countnumberHow many elements to leave out
arrayT[]Source array