Class NatFloat
- Namespace
- Vintagestory.API.MathTools
- Assembly
- VintagestoryAPI.dll
A more natural random number generator (nature usually doesn't grow by the exact same numbers nor does it completely randomly) Open in GitHub
[DocumentAsJson]
public class NatFloat : INatFloat, IEquatable<NatFloat>
- Inheritance
-
NatFloat
- Implements
- Inherited Members
- Extension Methods
Examples
"quantity": {
"dist": "strongerinvexp",
"avg": 6,
"var": 4
}
"quantity": {
"avg": 4,
"var": 2
}
Constructors
NatFloat(float, float, EnumDistribution)
public NatFloat(float averagevalue, float variance, EnumDistribution distribution)
Parameters
averagevaluefloatvariancefloatdistributionEnumDistribution
Fields
avg
The average value for the random float.
[DocumentAsJson("Recommended", "0", false)]
public float avg
Field Value
dist
The type of distribution to use that determines the commodity of values.
[DocumentAsJson("Optional", "UNIFORM", false)]
public EnumDistribution dist
Field Value
offset
A full offset to apply to any values returned.
[DocumentAsJson("Optional", "0", false)]
public float offset
Field Value
var
The variation for the random float.
[DocumentAsJson("Recommended", "0", false)]
public float var
Field Value
Properties
Average
public float Average { get; }
Property Value
One
Always 1
public static NatFloat One { get; }
Property Value
Type
public EnumINatFloatType Type { get; }
Property Value
Zero
Always 0
public static NatFloat Zero { get; }
Property Value
Methods
ClampToRange(float)
Clamps supplied value to avg-var and avg+var
public float ClampToRange(float value)
Parameters
valuefloat
Returns
Clone()
public NatFloat Clone()
Returns
CreateFromBytes(ref BinarySpanReader)
public static NatFloat CreateFromBytes(ref BinarySpanReader reader)
Parameters
readerBinarySpanReader
Returns
Equals(object)
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current object.
Returns
Equals(NatFloat)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(NatFloat other)
Parameters
otherNatFloatAn object to compare with this object.
Returns
FromBytes(BinaryReader)
[Obsolete("Prefer using the BinarySpanReader overload.")]
public void FromBytes(BinaryReader reader)
Parameters
readerBinaryReader
FromBytes(ref BinarySpanReader)
public void FromBytes(ref BinarySpanReader reader)
Parameters
readerBinarySpanReader
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()
Returns
- int
A hash code for the current object.
ToBytes(BinaryWriter)
public void ToBytes(BinaryWriter writer)
Parameters
writerBinaryWriter
ToNatFloat()
public NatFloat ToNatFloat()
Returns
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
- string
A string that represents the current object.
addOffset(float)
public NatFloat addOffset(float value)
Parameters
valuefloat
Returns
copyWithOffset(float)
public NatFloat copyWithOffset(float value)
Parameters
valuefloat
Returns
create(EnumDistribution, float, float)
public static NatFloat create(EnumDistribution distribution, float averagevalue, float variance)
Parameters
distributionEnumDistributionaveragevaluefloatvariancefloat
Returns
createDirac(float, float)
public static NatFloat createDirac(float averagevalue, float variance)
Parameters
Returns
createFromBytes(BinaryReader)
[Obsolete("Prefer using the BinarySpanReader overload.")]
public static NatFloat createFromBytes(BinaryReader reader)
Parameters
readerBinaryReader
Returns
createGauss(float, float)
public static NatFloat createGauss(float averagevalue, float variance)
Parameters
Returns
createInvGauss(float, float)
public static NatFloat createInvGauss(float averagevalue, float variance)
Parameters
Returns
createInvexp(float, float)
public static NatFloat createInvexp(float averagevalue, float variance)
Parameters
Returns
createNarrowGauss(float, float)
public static NatFloat createNarrowGauss(float averagevalue, float variance)
Parameters
Returns
createStrongInvexp(float, float)
public static NatFloat createStrongInvexp(float averagevalue, float variance)
Parameters
Returns
createStrongerInvexp(float, float)
public static NatFloat createStrongerInvexp(float averagevalue, float variance)
Parameters
Returns
createTri(float, float)
public static NatFloat createTri(float averagevalue, float variance)
Parameters
Returns
createUniform(float, float)
public static NatFloat createUniform(float averagevalue, float variance)
Parameters
Returns
nextFloat()
public float nextFloat()
Returns
nextFloat(float)
public float nextFloat(float multiplier)
Parameters
multiplierfloat
Returns
nextFloat(float, Random)
public float nextFloat(float multiplier, Random rand)
Parameters
Returns
nextFloat(float, IRandom)
public float nextFloat(float multiplier, IRandom rand)
Parameters
Returns
setOffset(float)
public NatFloat setOffset(float offset)
Parameters
offsetfloat
Returns
Operators
operator ==(NatFloat, NatFloat)
public static bool operator ==(NatFloat left, NatFloat right)
Parameters
Returns
operator !=(NatFloat, NatFloat)
public static bool operator !=(NatFloat left, NatFloat right)