Table of Contents

Class RandomHelper

Namespace
Volo.Abp
Assembly
Volo.Abp.Core.dll

A shortcut to use Random class. Also provides some useful methods.

public static class RandomHelper
Inheritance
RandomHelper
Inherited Members

Methods

GenerateRandomizedList<T>(IEnumerable<T>)

Generates a randomized list from given enumerable.

public static List<T> GenerateRandomizedList<T>(IEnumerable<T> items)

Parameters

items IEnumerable<T>

items

Returns

List<T>

Type Parameters

T

Type of items in the list

GetRandom()

Returns a nonnegative random number.

public static int GetRandom()

Returns

int

A 32-bit signed integer greater than or equal to zero and less than MaxValue.

GetRandom(int)

Returns a nonnegative random number less than the specified maximum.

public static int GetRandom(int maxValue)

Parameters

maxValue int

The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to zero.

Returns

int

A 32-bit signed integer greater than or equal to zero, and less than maxValue; that is, the range of return values ordinarily includes zero but not maxValue. However, if maxValue equals zero, maxValue is returned.

GetRandom(int, int)

Returns a random number within a specified range.

public static int GetRandom(int minValue, int maxValue)

Parameters

minValue int

The inclusive lower bound of the random number returned.

maxValue int

The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue.

Returns

int

A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not maxValue. If minValue equals maxValue, minValue is returned.

GetRandomOfList<T>(IList<T>)

Gets random item from the given list.

public static T GetRandomOfList<T>(IList<T> list)

Parameters

list IList<T>

List of object to select a random one

Returns

T

Type Parameters

T

Type of the objects

GetRandomOf<T>(params T[])

Gets random of given objects.

public static T GetRandomOf<T>(params T[] objs)

Parameters

objs T[]

List of object to select a random one

Returns

T

Type Parameters

T

Type of the objects