Documentation
¶
Overview ¶
RandomNumberGenerator is a class for generating pseudo-random numbers. It currently uses PCG32.
Note: The underlying algorithm is an implementation detail and should not be depended upon.
To generate a random float number (within a given range) based on a time-dependent seed:
package main import "graphics.gd/classdb/RandomNumberGenerator" func ExampleRandomNumberGenerator() { var rng = RandomNumberGenerator.New() var my_random_number = rng.RandfRange(-10.0, 10.0) _ = my_random_number }
Index ¶
- type Advanced
- type Any
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRandomNumberGenerator() Instance
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) ID() ID
- func (self Instance) MoreArgs() MoreArgs
- func (self Instance) RandWeighted(weights []float32) int
- func (self Instance) Randf() Float.X
- func (self Instance) RandfRange(from Float.X, to Float.X) Float.X
- func (self Instance) Randfn() Float.X
- func (self Instance) Randi() int
- func (self Instance) RandiRange(from int, to int) int
- func (self Instance) Randomize()
- func (self Instance) Seed() int
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) SetSeed(value int)
- func (self Instance) SetState(value int)
- func (self Instance) State() int
- func (self Instance) Virtual(name string) reflect.Value
- type MoreArgs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsRandomNumberGenerator ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.RandomNumberGenerator
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func (Instance) AsRandomNumberGenerator ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) MoreArgs ¶
MoreArgs enables certain functions to be called with additional 'optional' arguments.
func (Instance) RandWeighted ¶
Returns a random index with non-uniform weights. Prints an error and returns -1 if the array is empty.
func (Instance) RandfRange ¶
Returns a pseudo-random float between 'from' and 'to' (inclusive).
func (Instance) Randfn ¶
Returns a normally-distributed, pseudo-random floating-point number from the specified 'mean' and a standard 'deviation'. This is also known as a Gaussian distribution.
Note: This method uses the Box-Muller transform algorithm.
func (Instance) Randi ¶
Returns a pseudo-random 32-bit unsigned integer between 0 and 4294967295 (inclusive).
func (Instance) RandiRange ¶
Returns a pseudo-random 32-bit signed integer between 'from' and 'to' (inclusive).
func (Instance) Randomize ¶
func (self Instance) Randomize()
Sets up a time-based seed for this RandomNumberGenerator instance. Unlike the standard random number generation functions, different RandomNumberGenerator instances can use different seeds.
func (Instance) Seed ¶
Initializes the random number generator state based on the given seed value. A given seed will give a reproducible sequence of pseudo-random numbers.
Note: The RNG does not have an avalanche effect, and can output similar random streams given similar seeds. Consider using a hash function to improve your seed quality if they're sourced externally.
Note: Setting this property produces a side effect of changing the internal State, so make sure to initialize the seed before modifying the State:
Note: The default value of this property is pseudo-random, and changes when calling Randomize. The 0 value documented here is a placeholder, and not the actual default seed.
func (Instance) State ¶
The current state of the random number generator. Save and restore this property to restore the generator to a previous state:
Note: Do not set state to arbitrary values, since the random number generator requires the state to have certain qualities to behave properly. It should only be set to values that came from the state property itself. To initialize the random number generator with arbitrary input, use Seed instead.
Note: The default value of this property is pseudo-random, and changes when calling Randomize. The 0 value documented here is a placeholder, and not the actual default state.
type MoreArgs ¶
type MoreArgs [1]gdclass.RandomNumberGenerator
MoreArgs is a container for Instance functions with additional 'optional' arguments.
func (MoreArgs) Randfn ¶
Returns a normally-distributed, pseudo-random floating-point number from the specified 'mean' and a standard 'deviation'. This is also known as a Gaussian distribution.
Note: This method uses the Box-Muller transform algorithm.