# Random

The Random data type generates pseudorandom numbers and directions.

## 概要

### 方法

• Returns a pseudorandom integer uniformly distributed over [min, max].

• Returns a pseudorandom number uniformly distributed over [0, 1].

• NextNumber(min : number,max : number)

Returns a pseudorandom number uniformly distributed over [min, max].

• Shuffle(tb : table):void

Uniformly shuffles a table in-place.

• Returns a unit vector with a pseudorandom direction.

• Returns a new Random object with the same state as the original.

## コンストラクタ

### new

seed: number

#### コードサンプル

Datatype.Random

``````local max = 2147483647 -- use a large integer
local seed = math.random(max)
local generator = Random.new(seed)``````

## 方法

### NextInteger

Returns a pseudorandom integer uniformly distributed over [min, max].

min: number
max: number

### NextNumber

Returns a pseudorandom number uniformly distributed over [0, 1].

### NextNumber

Returns a pseudorandom number uniformly distributed over [min, max].

min: number
max: number

### Shuffle

void

Uniformly shuffles the array part of tb in-place using NextInteger to pick indices. If there are any nil "holes" in the array part of the table, Shuffle throws an error, since shuffling could change the length.

The hash part of tb is ignored. No metamethods of tb are invoked.

The shuffle is defined to be a Fisher-Yates shuffle so the number of NextInteger calls is guaranteed to be consistent between engine versions for a given size of table.

tb: table

void

### NextUnitVector

Returns a unit vector with a pseudorandom direction. Vectors returned from this function are uniformly distributed over the unit sphere.

#### 戻り値

A unit vector with a pseudorandom direction.

### Clone

Returns a new Random object with the same state as the original.