Skip to content

Commit 57c4dbd

Browse files
committed
updated rng extensions
1 parent 078466f commit 57c4dbd

18 files changed

+707
-21
lines changed

Code/Runtime/OlegHcp/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,56 @@ public class MyClass
381381
}
382382
```
383383

384+
Linear increasing:
385+
386+
```csharp
387+
float[] floats = new float[1000];
388+
for (int i = 0; i < floats.Length; i++)
389+
floats[i] = i * 0.1f;
390+
```
391+
392+
![](https://raw.githubusercontent.com/oleghcp/UnityTools/master/_images/RngLinear.png)
393+
394+
Ordinary random number generating:
395+
396+
```csharp
397+
floats[i] = rng.Next(0f, 100f);
398+
```
399+
400+
![](https://raw.githubusercontent.com/oleghcp/UnityTools/master/_images/RngRandom.png)
401+
402+
Ascending:
403+
404+
```csharp
405+
floats[i] = rng.Ascending(0f, 100f);
406+
```
407+
408+
![](https://raw.githubusercontent.com/oleghcp/UnityTools/master/_images/RngAscending.png)
409+
410+
Descending:
411+
412+
```csharp
413+
floats[i] = rng.Descending(0f, 100f);
414+
```
415+
416+
![](https://raw.githubusercontent.com/oleghcp/UnityTools/master/_images/RngDescending.png)
417+
418+
MinMax:
419+
420+
```csharp
421+
floats[i] = rng.MinMax(0f, 100f);
422+
```
423+
424+
![](https://raw.githubusercontent.com/oleghcp/UnityTools/master/_images/RngMinMax.png)
425+
426+
Average:
427+
428+
```csharp
429+
floats[i] = rng.Average(0f, 100f);
430+
```
431+
432+
![](https://raw.githubusercontent.com/oleghcp/UnityTools/master/_images/RngAverage.png)
433+
384434
## RectUtility
385435

386436
```csharp

Code/Runtime/OlegHcp/RngExtensions.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static int RandomFlag(this IRng self, BitList mask)
221221
/// Returns a random float number between min [inclusive] and max [inclusive] with chance offset to max values.
222222
/// </summary>
223223
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
224-
public static float Ascending(this IRng self, float min, float max, float offsetIntensity)
224+
public static float Ascending(this IRng self, float min, float max, float offsetIntensity = 1f)
225225
{
226226
if (min < max)
227227
return AscendingInternal(self, min, max, offsetIntensity);
@@ -232,7 +232,7 @@ public static float Ascending(this IRng self, float min, float max, float offset
232232
throw ThrowErrors.MinMax(nameof(min), nameof(max));
233233
}
234234

235-
private static float AscendingInternal(IRng self, float min, float max, float offsetIntensity)
235+
private static float AscendingInternal(IRng self, float min, float max, float offsetIntensity = 1f)
236236
{
237237
float range = max - min;
238238
float rnd = self.Next(0f, 1f);
@@ -243,7 +243,7 @@ private static float AscendingInternal(IRng self, float min, float max, float of
243243
/// Returns a random float number within range (min/max inclusive) with chance offset to max values.
244244
/// </summary>
245245
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
246-
public static float Ascending(this IRng self, in Diapason range, float offsetIntensity)
246+
public static float Ascending(this IRng self, in Diapason range, float offsetIntensity = 1f)
247247
{
248248
return Ascending(self, range.Min, range.Max, offsetIntensity);
249249
}
@@ -252,7 +252,7 @@ public static float Ascending(this IRng self, in Diapason range, float offsetInt
252252
/// Returns a random float number within range (min/max inclusive) with chance offset to max values.
253253
/// </summary>
254254
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
255-
public static float Ascending(this IRng self, in (float min, float max) range, float offsetIntensity)
255+
public static float Ascending(this IRng self, in (float min, float max) range, float offsetIntensity = 1f)
256256
{
257257
return Ascending(self, range.min, range.max, offsetIntensity);
258258
}
@@ -261,7 +261,7 @@ public static float Ascending(this IRng self, in (float min, float max) range, f
261261
/// Returns a random float number between min [inclusive] and max [inclusive] with chance offset to min values.
262262
/// </summary>
263263
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
264-
public static float Descending(this IRng self, float min, float max, float offsetIntensity)
264+
public static float Descending(this IRng self, float min, float max, float offsetIntensity = 1f)
265265
{
266266
if (min < max)
267267
return DescendingInternal(self, min, max, offsetIntensity);
@@ -272,7 +272,7 @@ public static float Descending(this IRng self, float min, float max, float offse
272272
throw ThrowErrors.MinMax(nameof(min), nameof(max));
273273
}
274274

275-
private static float DescendingInternal(IRng self, float min, float max, float offsetIntensity)
275+
private static float DescendingInternal(IRng self, float min, float max, float offsetIntensity = 1f)
276276
{
277277
float range = max - min;
278278
float rnd = self.Next(0f, 1f);
@@ -283,7 +283,7 @@ private static float DescendingInternal(IRng self, float min, float max, float o
283283
/// Returns a random float number within range (min/max inclusive) with chance offset to min values.
284284
/// </summary>
285285
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
286-
public static float Descending(this IRng self, in Diapason range, float offsetIntensity)
286+
public static float Descending(this IRng self, in Diapason range, float offsetIntensity = 1f)
287287
{
288288
return Descending(self, range.Min, range.Max, offsetIntensity);
289289
}
@@ -292,7 +292,7 @@ public static float Descending(this IRng self, in Diapason range, float offsetIn
292292
/// Returns a random float number within range (min/max inclusive) with chance offset to min values.
293293
/// </summary>
294294
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
295-
public static float Descending(this IRng self, in (float min, float max) range, float offsetIntensity)
295+
public static float Descending(this IRng self, in (float min, float max) range, float offsetIntensity = 1f)
296296
{
297297
return Descending(self, range.min, range.max, offsetIntensity);
298298
}
@@ -301,7 +301,7 @@ public static float Descending(this IRng self, in (float min, float max) range,
301301
/// Returns a random float number between min [inclusive] and max [inclusive] with chance offset to min and max values.
302302
/// </summary>
303303
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
304-
public static float MinMax(this IRng self, float min, float max, float offsetIntensity)
304+
public static float MinMax(this IRng self, float min, float max, float offsetIntensity = 1f)
305305
{
306306
if (min < max)
307307
{
@@ -319,7 +319,7 @@ public static float MinMax(this IRng self, float min, float max, float offsetInt
319319
/// Returns a random float number within range (min/max inclusive) with chance offset to min and max values.
320320
/// </summary>
321321
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
322-
public static float MinMax(this IRng self, in Diapason range, float offsetIntensity)
322+
public static float MinMax(this IRng self, in Diapason range, float offsetIntensity = 1f)
323323
{
324324
return MinMax(self, range.Min, range.Max, offsetIntensity);
325325
}
@@ -328,7 +328,7 @@ public static float MinMax(this IRng self, in Diapason range, float offsetIntens
328328
/// Returns a random float number within range (min/max inclusive) with chance offset to min and max values.
329329
/// </summary>
330330
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
331-
public static float MinMax(this IRng self, in (float min, float max) range, float offsetIntensity)
331+
public static float MinMax(this IRng self, in (float min, float max) range, float offsetIntensity = 1f)
332332
{
333333
return MinMax(self, range.min, range.max, offsetIntensity);
334334
}
@@ -337,7 +337,7 @@ public static float MinMax(this IRng self, in (float min, float max) range, floa
337337
/// Returns a random float number between min [inclusive] and max [inclusive] with chance offset to average values.
338338
/// </summary>
339339
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
340-
public static float Average(this IRng self, float min, float max, float offsetIntensity)
340+
public static float Average(this IRng self, float min, float max, float offsetIntensity = 1f)
341341
{
342342
if (min < max)
343343
{
@@ -355,7 +355,7 @@ public static float Average(this IRng self, float min, float max, float offsetIn
355355
/// Returns a random float number within range (min/max inclusive) with chance offset to average values.
356356
/// </summary>
357357
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
358-
public static float Average(this IRng self, in Diapason range, float offsetIntensity)
358+
public static float Average(this IRng self, in Diapason range, float offsetIntensity = 1f)
359359
{
360360
return Average(self, range.Min, range.Max, offsetIntensity);
361361
}
@@ -364,7 +364,7 @@ public static float Average(this IRng self, in Diapason range, float offsetInten
364364
/// Returns a random float number within range (min/max inclusive) with chance offset to average values.
365365
/// </summary>
366366
/// <param name="offsetIntensity">Offset intensity from zero to infinity. There is no offset if intensity is zero.</param>
367-
public static float Average(this IRng self, in (float min, float max) range, float offsetIntensity)
367+
public static float Average(this IRng self, in (float min, float max) range, float offsetIntensity = 1f)
368368
{
369369
return Average(self, range.min, range.max, offsetIntensity);
370370
}

_images/AnimationClipEditor.png.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_images/MeshRendererEditor.png.meta

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_images/RngAscending.png

22.4 KB
Loading

_images/RngAscending.png.meta

Lines changed: 104 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_images/RngAverage.png

22.3 KB
Loading

0 commit comments

Comments
 (0)