Skip to content
Reference > Classes

Rand

Definition

Rand var = .... ;

Extends

Extended By

None

Method Summary

Owner Name Return Type Description
Rand constructor(seed, secure) Rand Creates a new Randomizer, used for generating random numbers. If a seed is provided, then the numbers generated are the same across runs.
Object getClassName() String Returns the string name of this object's class type.
Rand nextBoolean() Boolean Returns a random Boolean value.
Rand nextDouble(min, max) Double Returns a random Double between min and max values.
Rand nextGaussian() Double Return a random signed Double with a mean of 0 and standard deviation of 1.
Rand nextGuid() String Returns a random string.
Rand nextInt(min, max) Integer Returns a random Integer between min and max values.
Rand nextUUID() UUID Returns a randomly generated version 4 UUID object.
Rand shuffle(list) List Returns a new list with the values' positions randomly shuffled.
Object toJson() String Returns a string of a json representation of this object.

Method Definitions


constructor(seed,secure)

Rand rand = new Rand(Number seed, Boolean secure)

Description

Creates a new Randomizer, used for generating random numbers. If a seed is provided, then the numbers generated are the same across runs.

Parameter Definition

Name Type Description
seed Number  seed for repeatability. If nullm then the seed is random
secure Boolean  if true, then secure. if null or false, then not secure

Example 1

1
2
3
Rand r = new Rand();

// r = java.util.Random@f9b5552

Example 2

1
2
3
Rand r = new Rand(1,true);

// r = NativePRNG

getClassName()

String Object::getClassName()

Description

Returns the string name of this object's class type.

Example 14

1
2
3
4
Rand r = new Rand();
r.getClassName();

// r.getClassName() = Rand

nextBoolean()

Boolean Rand::nextBoolean()

Description

Returns a random Boolean value.

Example 1

1
2
3
4
Rand r = new Rand();
r.nextBoolean();

// r.nextBoolean() = true

nextDouble(min,max)

Double Rand::nextDouble(Number min, Number max)

Description

Returns a random Double between min and max values.

Parameter Definition

Name Type Description
min Number  minimum number to be returned (inclusive). If null, then 0
max Number  maximum number to be returned (exclusive). If null, then 1

Example 1

1
2
3
4
Rand r = new Rand();
r.nextDouble(0,10);

// r.nextDouble(0,10) = 2.9434065856887965

nextGaussian()

Double Rand::nextGaussian()

Description

Return a random signed Double with a mean of 0 and standard deviation of 1.

Example 1

1
2
3
4
Rand r = new Rand();
r.nextGaussian();

// r.nextGaussian() = -0.5731770639567692

nextGuid()

String Rand::nextGuid()

Description

Returns a random string.

Example 1

1
2
3
4
Rand r = new Rand();
r.nextGuid();

// r.nextGuid() = 9de62cbf-a0b0-a855-58ba-a61d82f1e8d6

nextInt(min,max)

Integer Rand::nextInt(Number min, Number max)

Description

Returns a random Integer between min and max values.

Parameter Definition

Name Type Description
min Number  minimum number to be returned (inclusive). If null, then 0
max Number  maximum number to be returned (exclusive). If null, then 1

Example 1

1
2
3
4
Rand r = new Rand();
r.nextInt(0,10);

// r.nextInt(0,10) = 6

nextUUID()

UUID Rand::nextUUID()

Description

Returns a randomly generated version 4 UUID object.

Example 1

1
2
3
4
Rand r = new Rand();
r.nextUUID();

// r.nextUUID() = de52873e-f422-4436-875e-25bd4f748019

shuffle(list)

List Rand::shuffle(List list)

Description

Returns a new list with the values' positions randomly shuffled.

Parameter Definition

Name Type Description
list List  list of values to shuffle

Example 1

1
2
3
4
5
Rand r = new Rand();
List l = new List("a","b","c");
r.shuffle(l);

// r.shuffle(l) = [a, c, b]

toJson()

String Object::toJson()

Description

Returns a string of a json representation of this object.

Example 14

1
2
3
4
Rand r = new Rand();
r.toJson();

// r.toJson() = "java.util.Random@21f9277b"