Example #1
0
        private void btnRandSnakeColor_Click(object sender, EventArgs e)
        {
            RandomOrgApiClient randOrgClient = new RandomOrgApiClient(apiKey);
            int randomNumberTest             = Generate.GetRandom() % 255;

            Response randomOrgNums = randOrgClient.GenerateIntegers(3, 0, 255);

            txtR.Text = randomOrgNums.Integers[0].ToString();
            txtG.Text = randomOrgNums.Integers[1].ToString();
            txtB.Text = randomOrgNums.Integers[2].ToString();
        }
Example #2
0
 public static int GetRandom(int start, int finish)
 {
     try // first try the API. Since we are limited in # of uses, it will eventually stop working so you need to use a regular random number generator
     {
         Response r = nacho.GenerateIntegers(1, start, finish, true, false);
         return(r.Integers[0]);
     }
     catch //use built in random number generator if there's no internet connection, or the API doesn't work.
     {
         return(rnd.Next(start, finish));
     }
 }
Example #3
0
        private void ThreadGet()
        {
            Result = null;
            Response R  = ROClient.GenerateIntegers(1, 0, Items.Count - 1);
            int      ri = R.Integers[0];

            if (ri == -1)
            {
                MessageBox.Show("random.org API key invalid. Please enter a valid key in file key.ini");
                return;
            }
            Result = Items[ri];
        }
Example #4
0
        public string Generate(int size)
        {
            if (!IsNetworkAvailable())
            {
                throw new Exception("Network is not reachable");
            }

            var client   = new RandomOrgApiClient("82157e8f-726c-456d-a160-1f5ea2dd2447");
            var response = client.GenerateIntegers(size, 0, 31);

            StringBuilder sb = new StringBuilder(size);

            foreach (int n in response.Integers)
            {
                sb.Append(CharacterSet.list[n]);
            }

            return(sb.ToString());
        }