mirror of
https://github.com/ENSL/NS.git
synced 2024-11-21 20:21:14 +00:00
Fixed randomness
* Fixed mistake that caused random values to follow a constant pattern
This commit is contained in:
parent
36318cd1d4
commit
ef7e7a9178
1 changed files with 7 additions and 0 deletions
|
@ -403,6 +403,7 @@ Vector UTIL_RandomPointOnCircle(const Vector origin, const float radius)
|
|||
{
|
||||
Vector result;
|
||||
|
||||
srand(time(NULL));
|
||||
float random = ((float)rand()) / (float)RAND_MAX;
|
||||
|
||||
float a = random * (MATH_PI * 2);
|
||||
|
@ -642,6 +643,7 @@ float fInterpConstantTo(float start, float end, float DeltaTime, float InterpSpe
|
|||
|
||||
float frandrange(float MinValue, float MaxValue)
|
||||
{
|
||||
srand(time(NULL));
|
||||
return ((float(rand()) / float(RAND_MAX)) * (MaxValue - MinValue)) + MinValue;
|
||||
}
|
||||
|
||||
|
@ -649,11 +651,14 @@ int irandrange(int MinValue, int MaxValue)
|
|||
{
|
||||
if (MinValue == MaxValue) { return MinValue; }
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
return MinValue + rand() / (RAND_MAX / (MaxValue - MinValue + 1) + 1);
|
||||
}
|
||||
|
||||
bool randbool()
|
||||
{
|
||||
srand(time(NULL));
|
||||
return (rand() & 1);
|
||||
}
|
||||
|
||||
|
@ -661,6 +666,8 @@ Vector random_unit_vector_within_cone(const Vector Direction, double cone_half_a
|
|||
{
|
||||
Vector Result = ZERO_VECTOR;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
double u = ((double)rand() / RAND_MAX) * 2 - 1; // random number in [-1, 1]
|
||||
double phi = ((double)rand() / RAND_MAX) * 2 * M_PI; // random number in [0, 2*pi]
|
||||
double r = sqrt(1 - u * u);
|
||||
|
|
Loading…
Reference in a new issue