# SecureRandom

class
**SecureRandom** (View source)

Library for normalizing bytes returned by secure random byte generators.

SecureRandom takes bytes generated by secure random byte generators and normalizes (i.e. provides even distribution) for other common usages, such as generation of integers, floats and randomizing arrays.

## Methods

Returns a number of random bytes.

Returns a random integer between two positive integers (inclusive).

Returns a random float between 0 and 1 (excluding the number 1).

Returns a random float between 0 and 1 (inclusive).

Returns a number of randomly selected elements from the array.

Returns one randomly selected value from the array.

Returns the array with the elements reordered in a random order.

Returns a random sequence of values.

Returns a random UUID version 4 identifier.

## Details

###
at line 53
```
```**__construct**(Generator $generator = null)

**__construct**(Generator $generator = null)

Creates a new instance of SecureRandom.

You can either provide a generator to use for generating random bytes or give null as the argument to use default generators. If null is provided, the constructor will attempt to create the random byte generators in the following order until it finds one that is supported:

- Internal
- RandomReader
- Mcrypt
- OpenSSL

Note that since most cases require non-blocking random generation, the default generators use /dev/urandom as the random source. If you do not think this provides enough security, create the desired random generator using /dev/random as the source.

###
at line 93
```
string
```**getBytes**(int $count)

**getBytes**(int $count)

Returns a number of random bytes.

###
at line 111
```
int
```**getInteger**(int $min, int $max)

**getInteger**(int $min, int $max)

Returns a random integer between two positive integers (inclusive).

###
at line 139
```
float
```**getRandom**()

**getRandom**()

Returns a random float between 0 and 1 (excluding the number 1).

###
at line 157
```
float
```**getFloat**()

**getFloat**()

Returns a random float between 0 and 1 (inclusive).

###
at line 174
```
array
```**getArray**(array $array, int $count)

**getArray**(array $array, int $count)

Returns a number of randomly selected elements from the array.

This method returns randomly selected elements from the array. The number of elements is determined by by the second argument. The elements are returned in random order but the keys are preserved.

###
at line 201
```
mixed
```**choose**(array $array)

**choose**(array $array)

Returns one randomly selected value from the array.

###
at line 217
```
array
```**shuffle**(array $array)

**shuffle**(array $array)

Returns the array with the elements reordered in a random order.

###
at line 244
```
array|string
```**getSequence**(string|array $choices, int $length)

**getSequence**(string|array $choices, int $length)

Returns a random sequence of values.

If a string is provided as the first argument, the method returns a string with characters selected from the provided string. The length of the returned string is determined by the second argument.

If an array is provided as the first argument, the method returns an array with elements selected from the provided array. The size of the returned array is determined by the second argument.

The functionality is similar to getArray(), except for the fact that the returned value can contain the same character or element multiple times. If the same character or element appears multiple times in the provided argument, it will increase the relative chance of it appearing in the returned value.

###
at line 290
```
string
```**getUuid**()

**getUuid**()

Returns a random UUID version 4 identifier.