言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Random.seed

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static var seed: int;
public static int seed;
public static seed as int

Description

乱数を生成する初期値を設定します

乱数生成は真にランダムでなく事前に決まった順番で番号を生成します(値の順番はほとんどの場合に問題ない形の乱数となります)。 乱数の値の選択は シード と呼ばれる値で選択されます。関数が使用される前のシステム時刻など任意の値からセットされます。これによりゲームが再生される度に同じ値が実行されて毎回同じゲームプレイとなることを避けます。しかし自身でシードをセットすることで同じ乱数の値を生成することが役に立つ場合もあります。 自身でシードをセットするのは例えば、ゲームレベルをプロシージャル生成する場合などです。乱数で選ばれた要素を使用することでシーンが任意で自然に見えるようになり、生成前にシードを事前にセットした値とすることが出来ます。これによりゲームが再生されるたびに同じ "ランダム" パターンが生成できます。これはゲームのストレージ要件を削減できます。任意でレベルを生成することが出来て、整数のシード値を使用してプロシージャルにレベルを好きなだけ生成できます。

private var noiseValues: float[];

function Start () {
	// If you comment out the following line, the sequence of random
	// values will be different each time you run. However, the sequence
	// will always be the same for any particular seed value.
	Random.seed = 42;
	
	noiseValues = new float[10];
	
	for (var i = 0; i < noiseValues.Length; i++) {
		noiseValues[i] = Random.value;
		print(noiseValues[i]);
	}
}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    private float[] noiseValues;
    void Start() {
        Random.seed = 42;
        noiseValues = new float[10];
        int i = 0;
        while (i < noiseValues.Length) {
            noiseValues[i] = Random.value;
            print(noiseValues[i]);
            i++;
        }
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	private noiseValues as (float)

	def Start() as void:
		Random.seed = 42
		noiseValues = array[of float](10)
		i as int = 0
		while i < noiseValues.Length:
			noiseValues[i] = Random.value
			print(noiseValues[i])
			i++