Cleanup Utility.cs

This commit is contained in:
amevarashi 2022-06-12 09:32:17 +05:00
parent 7e3034a300
commit 1e24da5312
1 changed files with 29 additions and 29 deletions

View File

@ -1,38 +1,38 @@
using System; using RimWorld;
using RimWorld; using System;
namespace RJWSexperience namespace RJWSexperience
{ {
public static class Utility public static class Utility
{ {
public static System.Random random = new System.Random(Environment.TickCount); private static readonly Random random = new Random(Environment.TickCount);
public static float RandGaussianLike(float min, float max, int iterations = 3) public static float RandGaussianLike(float min, float max, int iterations = 3)
{ {
double res = 0; double res = 0;
for (int i = 0; i < iterations; i++) for (int i = 0; i < iterations; i++)
{ {
res += random.NextDouble(); res += random.NextDouble();
} }
res = res / iterations; res /= iterations;
return (float)res * (max - min) + min; return ((float)res).Denormalization(min, max);
} }
public static void SetTo(this Pawn_RecordsTracker records, RecordDef record, float value) public static void SetTo(this Pawn_RecordsTracker records, RecordDef record, float value)
{ {
float recordval = records.GetValue(record); float recordval = records.GetValue(record);
records.AddTo(record, value - recordval); records.AddTo(record, value - recordval);
} }
public static float Normalization(this float num, float min, float max) public static float Normalization(this float num, float min, float max)
{ {
return (num - min)/(max - min); return (num - min) / (max - min);
} }
public static float Denormalization(this float num, float min, float max) public static float Denormalization(this float num, float min, float max)
{ {
return num * (max - min) + min; return (num * (max - min)) + min;
} }
} }
} }