Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:07:28+00:00 2026-05-24T01:07:28+00:00

User enters numbers to 10 textbox and i sent them to an array. Now

  • 0

User enters numbers to 10 textbox and i sent them to an array. Now i want to generate random numbers from this array. What can i do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:07:29+00:00Added an answer on May 24, 2026 at 1:07 am

    Something like this:

    public class Randomizer<T>
    {
        private readonly Random _random = new Random();
        private readonly IList<T> _numbers;
        public Randomizer(IList<T> numbers)
        {
            _numbers = numbers;
        }
    
        public T Next()
        {
            int idx = _random.Next(0, _numbers.Count);
            return _numbers[idx];
        }
    }
    

    Usage:

    var r = new Randomizer<int>(new int[] { 10, 20, 30, 40, 50 });
    for (int i = 0; i < 100; i++)
         Console.Write(r.Next() + " ");
    

    Or do you want to shuffle the array?

    [Edit]

    To shuffle the array, you can use the Fisher–Yates shuffle shown in this post:

    // https://stackoverflow.com/questions/108819/110570#110570
    public class Shuffler
    {
        private Random rnd = new Random();
        public void Shuffle<T>(IList<T> array)
        {
            int n = array.Count;
            while (n > 1)
            {
                int k = rnd.Next(n);
                n--;
                T temp = array[n];
                array[n] = array[k];
                array[k] = temp;
            }
        }
    }
    

    If you want the interface to be same as the Randomizer class above, you can modify it to use the Shuffler class:

    public class Randomizer<T>
    {
        private readonly Shuffler _shuffler = new Shuffler();
        private readonly IList<T> _numbers;
        public Randomizer(IList<T> numbers)
        {
            _numbers = new List<T>(numbers);
            _shuffler.Shuffle(_numbers);
        }
    
        volatile int idx = 0;
        public T Next()
        {
            if (idx >= _numbers.Count)
            {
                _shuffler.Shuffle(_numbers);
                idx = 0;
            }
    
            return _numbers[idx++];
        }
    }
    

    Note that the code is not thread safe, so some locking should be implemented if Next method might be called simultaneously from multiple threads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox where the user enters a random string. I want to
Shouldn't this regex validator make sure the user enters something in the textbox? For
how can i get the numbers entered in textbox in an array. for example:
How do I check and see if a user enters only numbers and is
I want to validate the value a user enters in a text box, so
I have a textbox.T he user will be entering entering a number in this
The code below belongs to a binary search algorithm. The user enters numbers in
The code below belongs to a binary search algorithm. The user enters numbers in
I have a textbox in which I wanted a user to enter only numbers.
I want to first form a 3-digit code once a user enters some input

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.