mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
670 B
38 lines
670 B
namespace ErsatzTV.Core.Scheduling; |
|
|
|
public class CloneableRandom |
|
{ |
|
private readonly Random _random; |
|
private readonly int _seed; |
|
private int _count; |
|
|
|
public CloneableRandom(int seed) |
|
{ |
|
_seed = seed; |
|
_random = new Random(_seed); |
|
} |
|
|
|
public CloneableRandom Clone() |
|
{ |
|
var clone = new CloneableRandom(_seed); |
|
|
|
for (var i = 0; i < _count; i++) |
|
{ |
|
clone.Next(); |
|
} |
|
|
|
return clone; |
|
} |
|
|
|
public int Next() |
|
{ |
|
_count++; |
|
return _random.Next(); |
|
} |
|
|
|
public int Next(int maxValue) |
|
{ |
|
_count++; |
|
return _random.Next(maxValue); |
|
} |
|
}
|
|
|