Esempio n. 1
0
        public static void GetBigIntegerWithSpecifiedLength(ulong length)
        {
            using var random = new SecureRandom();
            var value = random.GetBigInteger(length);

            Assert.That(value.ToString().Length, Is.EqualTo((int)length));
        }
Esempio n. 2
0
 public static void GetBigIntegerWithZeroLength()
 {
     using var random = new SecureRandom();
     Assert.That(() => random.GetBigInteger(0),
                 Throws.TypeOf <ArgumentException>()
                 .And.Message.EqualTo("The number of digits cannot be zero. (Parameter 'numberOfDigits')"));
 }
 public void CreateBigIntegerWithZeroLength()
 {
     using(var random = new SecureRandom())
     {
         random.GetBigInteger(0);
     }
 }
        public void CreateBigIntegerWithLengthOf9()
        {
            const int length = 9;

            using(var random = new SecureRandom())
            {
                var value = random.GetBigInteger(length);
                Assert.AreEqual(length, value.ToString().Length);
            }
        }
Esempio n. 5
0
        private async void OnRunManyRandomCollatzOnServerClick(object sender, RoutedEventArgs e)
        {
            using (Cursors.Wait.Bind(() => this.Cursor))
            {
                this.Results.Text = string.Empty;
                var iterations = 0;

                if (int.TryParse(this.Iterations.Text, out iterations))
                {
                    var pauseTime = 0;
                    int.TryParse(this.PauseTime.Text, out pauseTime);

                    var random = new SecureRandom();

                    using (var writer = new StringWriter())
                    {
                        var responses = new List <Task <CollatzGetResponseMessage> >();

                        for (var i = 0; i < iterations; i++)
                        {
                            var value = random.GetBigInteger((ulong)random.Next(50, 200));
                            responses.Add(WebApiCalls.GetResponse(value, pauseTime));
                        }

                        await Task.WhenAll(responses);

                        foreach (var response in responses)
                        {
                            var result = response.Result;
                            writer.WriteLine(string.Format("Number: {0}, Iterations: {1}, Time: {2}",
                                                           result.Value, result.Iterations, result.Time));
                        }

                        this.Results.Text = writer.ToString();
                    }
                }
            }
        }