DataWeave Mock Data Generators Library icon

DataWeave Mock Data Generators Library

(0 reviews)

RandomHelpers

mocks::helpers::RandomHelpers

This module condenses helper functions for Number randomization in different formats.

Index

Functions

NameDescription
pickRandomReturns a random value from an array.
randomIntWithBaseReturns a random integer between two respective base and ceiling values.
If the base value is greater than the ceiling value, base is returned.
randomIntWithLengthReturns a random integer of a certain digit length.
Or 0 if the length is less than 1.
randomNumberReturns a random number between two respective base and ceiling values,
with the capability to specify the desired amount of decimal places.

Functions

pickRandom ↑↑

pickRandom<T>(options: Array<T>): T

Returns a random value from an array.

Parameters
NameTypeDescription
optionsArray<T>Array of values from which to pick.
Example

This example shows how pickRandom behaves under an arbitrary array.

Source
%dw 2.0
import * from mocks::helpers::RandomHelpers
---
pickRandom([1, "Nacho", 3])

Output
3

pickRandom(options: Null): Null

Helper function that enables pickRandom to work with a null value.


randomIntWithBase ↑↑

randomIntWithBase(base: Number, max: Number): Number

Returns a random integer between two respective base and ceiling values.
If the base value is greater than the ceiling value, base is returned.

Parameters
NameTypeDescription
baseNumberThe base value.
maxNumberThe ceiling value.
Example

This example shows how the randomIntWithBase function behaves for two arbitrary values.

Source
%dw 2.0
output application/json
import randomIntWithBase from mocks::helpers::RandomHelpers
---
randomIntWithBase(2,10)
Output
4

randomIntWithBase(base: Null, max: Any = null): Null

Helper function that enables randomIntWithBase to work with a null value.


randomIntWithBase(base: Any, max: Null): Null

Helper function that enables randomIntWithBase to work with a null value.


randomIntWithLength ↑↑

randomIntWithLength(len: Number): Number

Returns a random integer of a certain digit length.
Or 0 if the length is less than 1.

Parameters
NameTypeDescription
lenNumberThe desired lenght for the output number.
Example

This example shows how the randomIntWithLength behaves under different inputs.

Source
%dw 2.0
output application/json
import * from mocks::helpers::RandomHelpers
---
randomIntWithLength(20)

Output
71020173281033233000

randomIntWithLength(len: Null): Null

Helper function that enables randomIntWithLength to work with a null value.


randomNumber ↑↑

randomNumber(base: Number, max: Number, precision: Number): Number

Returns a random number between two respective base and ceiling values,
with the capability to specify the desired amount of decimal places.

If base > max, base is returned. If precision is a negative number, no decimal part is added.

Parameters
NameTypeDescription
baseNumberThe base value.
maxNumberThe ceiling value.
precisionNumberThe desired amount of decimal places to be returned.
Example

This example shows how the randomNumber behaves under different inputs.

Source
%dw 2.0
output application/json
import * from mocks::helpers::RandomHelpers
---
randomNumber(0,1,10)
Output
0.3294639395

randomNumber(base: Null, max: Any, precision: Any): Null

Helper function that enables randomNumber to work with a null value.


randomNumber(base: Any, max: Null, precision: Any): Null

Helper function that enables randomNumber to work with a null value.


randomNumber(base: Any, max: Any, precision: Null): Null

Helper function that enables randomNumber to work with a null value.



Reviews

TypeDataWeave Library
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onMar 23, 2022
Asset overview

Asset versions for 1.0.x

Asset versions
VersionActions
1.0.0