public string PickNext(IRandomSource random) { var l = Builders.Build <uint>(random) / (double)uint.MaxValue; return(Links .OrderBy(_ => Builders.Build <int>(random)) .Where(i => i.Probability > l) .Select(i => i.Value) .FirstOrDefault()); }
public string Generate(int maxLength, IRandomSource random) { ChainItem current = null; var result = new StringBuilder(); int count = 0; while (count < maxLength) { if (current == null) { current = _items.Values.Where(i => i.CanStart).OrderBy(_ => Builders.Build <int>(random)).First(); result.Append(current.Value); count++; continue; } if (current.CanFinish && Builders.Build <byte>(random) % 10 < 3) { result.Append(_endOfSequence + _separator); current = null; continue; } var next = current.PickNext(random); if (next == null) { result.Append(_endOfSequence + _separator); current = null; continue; } current = _items [next]; result.Append(_separator + current.Value); count++; } return(result.ToString()); }
static int Generate(IRandomSource source) { return(Math.Abs(Builders.Build <short>(source)) % 9000 + 1000); }
public T GetNext(IRandomSource source) { return(Builders.Build <T> (source)); }