/// <summary> /// Initializes this instance. /// </summary> public static void Initialize() { if (Base.Initialized) { return; } // Sentry.Initialize(); XorShift.Initialize(); ScFiles.Initialize(); CsvFiles.Initialize(); SoundFiles.Initialize(); Fingerprint.Initialize(); Home.Initialize(); Globals.Initialize(); ClientGlobals.Initialize(); MessageFactory.Initialize(); IpRequester.Initialize(); Tests.Initialize(); Base.Initialized = true;; }
/// <summary>Potentially gameplay-mutating logic for cue playback (modifies `random` and `cueStates`)</summary> public static PlayCueParameters GetParameters(Cue cue, XorShift random, ushort[] cueStates) { if (cue == null) { return new PlayCueParameters { soundIndex = NO_SOUND } } ; if (ReferenceEquals(cue, Cue.missingCue)) { return new PlayCueParameters { soundIndex = MISSING_CUE } } ; if (cue.SoundCount == 0) { return new PlayCueParameters { soundIndex = NO_SOUND } } ; PlayCueParameters result; result.cuePitch = cue.SelectPitch(random); result.soundIndex = cue.SelectSound(random, cueStates); Debug.Assert(result.soundIndex >= 0); return(result); } } }
public override void Solve(IOManager io) { var sw = new Stopwatch(); sw.Start(); var rand = new XorShift(); var id = io.ReadInt(); var size = io.ReadInt(); var maxColor = io.ReadInt(); var panels = new int[size][]; for (int row = 0; row < panels.Length; row++) { panels[row] = new int[size]; for (int column = 0; column < panels[row].Length; column++) { panels[row][column] = io.ReadChar() - '0'; } } var queryCount = 9999; io.WriteLine(queryCount); for (int i = 0; i < queryCount; i++) { io.WriteLine($"{rand.Next(size) + 1} {rand.Next(size) + 1} {rand.Next(maxColor) + 1}"); } }
/// <summary> /// Initializes a new instance of the <see cref="Device"/> class. /// </summary> /// <param name="Socket">The socket.</param> internal Device(Socket Socket) { this.Socket = Socket; this.Crypto = new Rjindael("88778f76fwe67r5f78wer678r9we7" + "nonce"); this.Random = new XorShift(Resources.Random.Next()); }
public void ConvolutionLLTest(int lengthA, int lengthB, ulong seed) { var rand = new XorShift(seed); var a = new long[lengthA]; var b = new long[lengthB]; for (int i = 0; i < a.Length; i++) { a[i] = rand.Next(1_000_000) - 500_000; } for (int i = 0; i < b.Length; i++) { b[i] = rand.Next(1_000_000) - 500_000; } var expected = new long[a.Length + b.Length - 1]; for (int i = 0; i < a.Length; i++) { for (int j = 0; j < b.Length; j++) { expected[i + j] += a[i] * b[j]; } } var actual = AtCoder.Math.ConvolutionLong(a, b); Assert.Equal(expected, actual); }
/// <summary> /// Initializes a new instance of the <see cref="Resources"/> class. /// </summary> internal static void Initialize() { Resources.Logger = LogManager.GetCurrentClassLogger(typeof(Resources)); Factory.Initialize(); CSV.Initialize(); LevelFile.Initialize(); Fingerprint.Initialize(); Globals.Initialize(); if (Constants.Database == DBMS.Mongo) { Mongo.Initialize(); } Resources.Redis = new Redis(); Resources.Regex = new Regex("[ ]{2,}", RegexOptions.Compiled); Resources.Players = new Players(); Resources.Clans = new Clans(); Resources.Chats = new Chats(); Resources.Battles = new Battles(); Resources.Random = new XorShift(); Resources.TCPGateway = new TCPServer(); Resources.UDPGateway = new UDPServer(); Resources.Started = true; Parser.Initialize(); EventsHandler.Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Resources"/> class. /// </summary> internal static void Initialize() { Resources.Logger = LogManager.GetCurrentClassLogger(typeof(Resources)); CSV.Initialize(); Home.Initialize(); Factory.Initialize(); Globals.Initialize(); Fingerprint.Initialize(); Resources.TCPGateway = new TCPServer(); Resources.UDPGateway = new UDPServer(); Resources.Database = new MySqlDatabase(); Resources.CacheSystem = new RedisDatabase(); Resources.Players = new Players(); Resources.Clans = new Clans(); Resources.Random = new XorShift(); Resources.BattleManager = new BattleManager(); Resources.Started = true; Parser.Initialize(); EventsHandler.Initialize(); Timers.Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Device"/> class. /// </summary> /// <param name="Socket">The socket.</param> internal Device(Socket Socket) { this.Socket = Socket; this.Crypto = new Rjindael(); this.Random = new XorShift(Resources.Random.Next()); }
/// <summary> /// Initializes a new instance of the <see cref="Resources"/> class. /// </summary> internal static void Initialize() { Resources.Logger = LogManager.GetCurrentClassLogger(typeof(Resources)); Factory.Initialize(); CSV.Initialize(); Home.Initialize(); Fingerprint.Initialize(); if (Constants.Database == DBMS.Mongo) { Mongo.Initialize(); } Resources.Redis = new Redis(); Resources.Players = new Players(); Resources.Random = new XorShift(); Resources.TCPGateway = new TCPServer(); Resources.UDPGateway = new UDPServer(); Resources.Started = true; Parser.Initialize(); EventsHandler.Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Resources"/> class. /// </summary> internal static void Initialize() { Resources.Logger = LogManager.GetCurrentClassLogger(typeof(Resources)); Resources.Sentry = new Sentry(Constants.SentryAPI, Constants.SentryID, Constants.UseSentry); #if DEBUG Console.WriteLine("Loaded " + Factory.Messages.Count + " messages, " + Factory.Commands.Count + " commands, and " + Factory.Debugs.Count + " debug commands."); #endif Resources.Redis = new Redis(); Resources.Parser = new Parser(); Resources.Fingerprint = new Fingerprint(); Resources.CSV = new CSV(); Resources.Home = new Home(); Resources.Npc = new NPC(); Resources.Helpers = new Helpers(); Resources.Checker = new Timers(); Resources.Players = new Players(); Resources.Clans = new Clans(); Resources.Battles = new Battles(); Resources.Chats = new WorldChats(); Resources.Random = new XorShift(); Resources.Cluster = new Cluster(); Resources.Test = new Test(); Resources.Gateway = new TCPServer(); Resources.UGateway = new UDPServer(); Resources.Events = new EventsHandler(); Resources.Started = true; }
/// <summary> /// Initializes a new instance of the <see cref="Resources"/> class. /// </summary> internal static void Initialize() { Resources.Logger = LogManager.GetCurrentClassLogger(typeof(Resources)); Factory.Initialize(); CSV.Initialize(); Home.Initialize(); Fingerprint.Initialize(); GameDatas.Initialize(); Resources.Gametools = new GameTools(); Resources.Redis = new Redis(); Resources.Players = new Players(); Resources.Clans = new Clans(); Resources.Battles = new Battles(); Resources.Random = new XorShift(); Resources.TCPGateway = new TCPServer(); Resources.UDPGateway = new UDPServer(); Resources.Started = true; Parser.Initialize(); EventsHandler.Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Device"/> class. /// </summary> /// <param name="Socket">The socket.</param> internal Device(Socket Socket) { this.Socket = Socket; this.Crypto = new Rjindael("asfddsfsd874397f7d98wq090qd80qw" + "nonce"); this.Random = new XorShift(Resources.Random.Next()); }
public ClientScenarios(IPAddress address) { AsyncTcp.Initialize(this); _address = address; _xorShifter = new XorShift(true); _random = new Random(); }
public TreapNode(T val) { this.val = val; priority = XorShift.Get(); leftMost = this; rightMost = this; count = 1; }
static void Main() { //XorShift乱数ジェネレータの初期化 // 論文デフォルトシード var r_def = new XorShift.defaultSeed(); // 固定値シード var r_const = new XorShift(100); // 時間シード var r = new XorShift(); //デフォルトシード値の取得 Console.WriteLine(">> defaults"); Console.WriteLine(String.Join(", ", XorShift.defaults)); //適用したシード値の取得 Console.WriteLine(">> seeds in r"); Console.WriteLine(String.Join(", ", r.seeds)); //乱数の生データを取得 Console.WriteLine(">> rand 0 to UInt32Max"); for (int i = 0; i < 5; i++) { Console.WriteLine(r_def.rand()); } //0-100の乱数(100含む)を整数で取得 Console.WriteLine(">> randInt 0 to 100"); for (int i = 0; i < 5; i++) { Console.WriteLine(r_const.randInt(0, 100)); } //0-1の乱数を浮遊小数点で取得 Console.WriteLine(">> randFloat 0 to 1"); for (int i = 0; i < 5; i++) { Console.WriteLine(r.randFloat()); } //静的配列のシャッフル //値渡しとなるので元の配列は破壊されない Console.WriteLine(">> shuffle Array"); int[] a = Enumerable.Range(0, 20).ToArray(); Console.WriteLine(String.Join(", ", r.shuffle(a))); Console.WriteLine(String.Join(", ", a)); //List<T>のシャッフル Console.WriteLine(">> shuffle List<T>"); var b = new List <int>(Enumerable.Range(0, 20)); Console.WriteLine(String.Join(", ", r.shuffle(b))); Console.WriteLine(String.Join(", ", b)); //今の乱数を回した回数 Console.WriteLine(">> randCount in r"); Console.WriteLine(r.randCount); }
public HardestMaze(int mazeSize, int robotCount, int targetCountEach, Square[] starts, Square[][] targets) { _mazeSize = mazeSize; _robotCount = robotCount; _targetCountEach = targetCountEach; _starts = starts; _targets = targets; _diffs = new Diff[] { new Diff(-1, 0), new Diff(1, 0), new Diff(0, -1), new Diff(0, 1) }; _xorShift = new XorShift(); }
public override IEnumerable <object> Solve(TextReader inputStream) { const double R = 1e15; const double RSquared = R * R; var sw = new Stopwatch(); sw.Start(); var n = inputStream.ReadInt(); var points = new Point[n]; for (int i = 0; i < points.Length; i++) { var(x, y) = inputStream.ReadValue <int, int>(); points[i] = new Point(x, y); } var counts = new int[n]; var countSum = 0; var rand = new XorShift(); while (sw.ElapsedMilliseconds < 1850) { var min = double.MaxValue; var index = -1; unchecked { var x = rand.NextDouble() * 2 * R - R; var y = rand.NextDouble() * 2 * R - R; if (x * x + y * y <= RSquared) { for (int i = 0; i < points.Length; i++) { var dist = points[i].GetDistanceSquared(x, y); if (dist < min) { index = i; min = dist; } } counts[index]++; countSum++; } } } foreach (var c in counts) { yield return((double)c / countSum); } }
public override void Solve(IOManager io) { var sw = new Stopwatch(); sw.Start(); var rand = new XorShift(); var _ = io.ReadInt(); var size = io.ReadInt(); var maxColor = io.ReadInt(); var colorMap = LoadMap(io, size); var(idMap, idCount) = GetIDs(colorMap); var tried = new bool[idCount]; var(queries, firstID) = TryFirst(colorMap, idMap, idCount, maxColor); tried[firstID] = true; var last = idCount - 1; int count = 1; bool end = false; var low = size * 42 / 100; var high = size * 58 / 100; for (int row = low; row < high && !end; row++) { for (int column = low; column < high && !end; column++) { var c = new Coordinate(row, column); if (!tried[idMap[row][column]]) { tried[idMap[row][column]] = true; var q = Try(c, colorMap, idMap, maxColor); if (q.Count < queries.Count) { queries = q; } count++; } if (sw.ElapsedMilliseconds >= 2850) { end = true; } } } io.WriteLine(queries.Count); while (queries.Count > 0) { io.WriteLine(queries.Dequeue()); } }
/// <summary> /// Sets the player. /// </summary> public void SetPlayer(Player Player, SpellDeck Deck, bool Npc) { if (!Npc) { this.Deck = Deck; this.Player = Player; int SpellCnt = Deck.SpellCount; byte[] Tmp = new byte[SpellCnt]; for (byte I = 0; I < SpellCnt; I++) { Tmp[I] = I; } int N = SpellCnt; while (N > 1) { int K = XorShift.Next(N + 1); byte Value = Tmp[K]; Tmp[K] = Tmp[N]; Tmp[N] = Value; --N; } int Cnt = Math.Min(4, SpellCnt); for (int I = 0; I < Cnt; I++) { this.Hand[I] = Tmp[I]; if (I > 0) { this.Hand[I] -= Tmp[I - 1]; } } for (int I = Cnt; I < SpellCnt; I++) { this.SpellQueue.Add(Tmp[I]); } // TODO : Mike, check this int Idx = 0; for (int I = 0; I < SpellCnt; I++) { Idx += this.Hand[I]; } } }
public void CreateFiveHundredRandomBytes() { var xorShift = new XorShift(true); var bytes0 = new byte[500]; var bytes1 = new byte[500]; xorShift.FillBuffer(bytes1, 0, bytes1.Length); Assert.NotEqual(bytes0, bytes1); }
public static async Task Main() { XorShifter = new XorShift(true); // Create a fixed sized random payload. RandomPayload = Encoding.UTF8.GetString(XorShifter.GetRandomBytes(20)); await SetupClientAsync() .ConfigureAwait(false); await Console.In.ReadLineAsync().ConfigureAwait(false); }
/// <summary> /// Gets a random spell. /// </summary> internal SpellData GetRandomSpell(XorShift Random, RarityData Data) { int Count = this.Spells[Data.Instance].Count; if (Count > 0) { return(this.Spells[Data.Instance][Random.Next(Count)]); } Logging.Info(this.GetType(), "GetRandomSpell() - No spell found for rarity: " + Data.Name); return(null); }
/// <summary> /// Gets a random spell. /// </summary> public SpellData GetRandomSpell(RarityData Data) { int Count = this.Spells[Data.Instance].Count; if (Count > 0) { return(this.Spells[Data.Instance][XorShift.Next(Count)]); } Logging.Warning(this.GetType(), "GetRandomSpell() - No spell found for rarity: " + Data.Name); return(null); }
public void Setup() { XorShift = new XorShift(true); Payload1 = XorShift.GetRandomBytes(1024); Payload2 = XorShift.GetRandomBytes(2048); Payload3 = XorShift.GetRandomBytes(4096); Payload4 = XorShift.GetRandomBytes(8192); HashKey = ArgonHash .GetHashKeyAsync(Passphrase, Salt, KeySize) .GetAwaiter() .GetResult(); }
public RngUInt32() { _chaCha8 = ChaCha.GetChaCha8Factory().Create(new ChaCha.Seed()); _chaCha12 = ChaCha.GetChaCha12Factory().Create(new ChaCha.Seed()); _chaCha20 = ChaCha.GetChaCha20Factory().Create(new ChaCha.Seed()); _pcg32 = Rngs.Pcg32.Create(0, 0); _mt1993764 = Rngs.Mt1993764.Create(0); _xorShift = Rngs.XorShift.Create(1, 1, 1, 1); _systemCryptoRng = Rngs.SystemCryptoRng.Create(); #pragma warning disable CS0618 _cryptoServiceProvider = Rngs.CryptoServiceProvider.Create(); #pragma warning restore CS0618 _random = new Random(42); }
/// <summary> /// Shuffles the specified list. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="List">The list.</param> public static void Shuffle <T>(this IList <T> List, XorShift Random) { int c = List.Count; while (c > 1) { c--; int r = Random.Next(c + 1); T Value = List[r]; List[r] = List[c]; List[c] = Value; } }
public void CreateRandomBytes() { var xorShift = new XorShift(); var bytes0 = new byte[1000]; var bytes1 = new byte[1000]; var bytes2 = new byte[1000]; xorShift.FillBuffer(bytes1, 0, bytes1.Length); xorShift.FillBuffer(bytes2, 0, bytes2.Length); Assert.NotEqual(bytes0, bytes1); Assert.NotEqual(bytes0, bytes2); Assert.NotEqual(bytes1, bytes2); }
public void Setup() { XorShift = new XorShift(true); Payload = XorShift.GetRandomBytes(1024); HashProvider = new Argon2ID_HashingProvider(); HashKey = HashProvider.GetHashKey(Passphrase, Salt, KeySize); EncryptionProvider = new AesGcmEncryptionProvider(HashKey); RecyclableEncryptionProvider = new RecyclableAesGcmEncryptionProvider(HashKey); //RecyclableManager.ConfigureNewStaticManagerWithDefaults(); EncryptedPayload = EncryptionProvider.Encrypt(Payload).ToArray(); }
public void Annealing(Stopwatch sw) { var random = new XorShift(); var count = 0; var startTime = sw.ElapsedMilliseconds; var temperature = CalculateTemp(startTime, startTime, TimeLimit); while (true) { if (count++ % 10000 == 0) { temperature = CalculateTemp(sw.ElapsedMilliseconds, startTime, TimeLimit); if (sw.ElapsedMilliseconds >= TimeLimit) { break; } } var cardA = random.Next(_takeOrderInv.Length); var cardB = random.Next(_takeOrderInv.Length); if (cardA == cardB) { continue; } var prev = CalculateLocal(cardA, cardB); Swap(ref _takeOrderInv[cardA], ref _takeOrderInv[cardB]); Swap(ref _takeOrder[_takeOrderInv[cardA]], ref _takeOrder[_takeOrderInv[cardB]]); Swap(ref _compressed[cardA], ref _compressed[cardB]); var next = CalculateLocal(cardA, cardB); // 大きい方が優秀 var diff = prev - next; if (!(diff >= 0 || random.NextDouble() <= Math.Exp(diff / temperature))) { Swap(ref _takeOrderInv[cardA], ref _takeOrderInv[cardB]); Swap(ref _takeOrder[_takeOrderInv[cardA]], ref _takeOrder[_takeOrderInv[cardB]]); Swap(ref _compressed[cardA], ref _compressed[cardB]); } } }
private void ConvolutionMod <T>(int lengthA, int lengthB, ulong seed) where T : struct, IStaticMod { var rand = new XorShift(seed); var a = new StaticModInt <T> [lengthA]; var b = new StaticModInt <T> [lengthB]; var aRaw = new ulong[lengthA]; var bRaw = new ulong[lengthB]; for (int i = 0; i < a.Length; i++) { aRaw[i] = rand.Next(); a[i] = StaticModInt <T> .Raw((int)(aRaw[i] % default(T).Mod)); } for (int i = 0; i < b.Length; i++) { bRaw[i] = rand.Next(); b[i] = StaticModInt <T> .Raw((int)(bRaw[i] % default(T).Mod)); } var expected = new StaticModInt <T> [a.Length + b.Length - 1]; for (int i = 0; i < a.Length; i++) { for (int j = 0; j < b.Length; j++) { expected[i + j] += a[i] * b[j]; } } // 各種オーバーロードについてテスト var actualModInt = AtCoder.Math.Convolution(a, b); var actualModIntSpan = AtCoder.Math.Convolution((ReadOnlySpan <StaticModInt <T> >)a, b); var actualInt = AtCoder.Math.Convolution <T>(a.Select(ai => ai.Value).ToArray(), b.Select(bi => bi.Value).ToArray()); var actualUInt = AtCoder.Math.Convolution <T>(a.Select(ai => (uint)ai.Value).ToArray(), b.Select(bi => (uint)bi.Value).ToArray()); var actualLong = AtCoder.Math.Convolution <T>(a.Select(ai => (long)ai.Value).ToArray(), b.Select(bi => (long)bi.Value).ToArray()); var actualULong = AtCoder.Math.Convolution <T>(aRaw, bRaw); Assert.Equal(expected, actualModInt); Assert.Equal(expected, actualModIntSpan.ToArray()); Assert.Equal(expected.Select(ei => ei.Value), actualInt); Assert.Equal(expected.Select(ei => (uint)ei.Value), actualUInt); Assert.Equal(expected.Select(ei => (long)ei.Value), actualLong); Assert.Equal(expected.Select(ei => (ulong)ei.Value), actualULong); }