Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Random.value

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

Switch to Manual
public static var value: float;
public static float value;

Description

Returns a random number between 0.0 [inclusive] and 1.0 [inclusive] (Read Only).

Both 0.0 and 1.0 may be returned by this property. This behaviour is different to that of many other random number generators which return a value less than but never exactly equal to 1.0.

// Generate a random color value.
function RandomColor() {
	// A different random value is used for each color component (if
	// the same is used for R, G and B, a shade of grey is produced).
	return new Color(Random.value, Random.value, Random.value);
}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { Color RandomColor() { return new Color(Random.value, Random.value, Random.value); } }