Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Text;
- namespace Random
- {
- public class Randomizer
- {
- private uint A;
- private uint B;
- private uint C;
- private uint Next = 12345;
- public const uint M = 16777216;
- public const int INum = 100;
- public const uint Div = M / INum;
- public Randomizer()
- {
- Initialize();
- }
- public void Initialize()
- {
- DateTime currentDate = DateTime.UtcNow;
- B = (uint)(currentDate.Ticks % 10000 + 1);
- B *= (uint)(currentDate.Second);
- B = (B % 2 != 0) ? B : B + 1;
- A = (uint)(currentDate.Ticks % 1000 + 1);
- A += (uint)(currentDate.Millisecond % 500);
- A = A * 4 + 1;
- C = (uint)(currentDate.Ticks % 100 + 800);
- Next = C;
- }
- public uint GenerateNext()
- {
- Next = (Next * A + B) % M;
- return Next;
- }
- public double[] GenerateSequence(int count)
- {
- var frequence = new double[INum];
- var next = C;
- var strBuilder = new StringBuilder();
- for (var i = 0; i < count; i++)
- {
- next = GenerateFromPrev(next);
- strBuilder.Append(next);
- strBuilder.Append(' ');
- var interval = next / Div;
- if (interval >= INum)
- frequence[frequence.Length - 1]++;
- else
- frequence[interval]++;
- }
- for (var i = 0; i < INum; i++)
- {
- if (frequence[i] == 0)
- continue;
- else
- frequence[i] = Math.Round(frequence[i] / count * 100, 2,
- MidpointRounding.AwayFromZero);
- }
- File.WriteAllText("output.txt", strBuilder.ToString());
- return frequence;
- }
- private uint GenerateFromPrev(uint prev)
- {
- return (prev * A + B) % M;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement