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

  • Home
  • SEARCH
  • 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 7905213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:23:37+00:00 2026-06-03T10:23:37+00:00

is there any good method to generate random even numbers with C#? I came

  • 0

is there any good method to generate random even numbers with C#? I came up with this code:

    Random RandString = new Random(0);

code:

    private void button6_Click(object sender, EventArgs e)
    {
        int min = 0;
        int max = 50;

        int rand = RandString.Next(min, max-1);
        while (rand % 2 == 1) // odd
        {
            rand = RandString.Next(min, max-1);
        }

        textBox4.Text = "" + rand;
    }

Problems with this code:

  • my current solution might not be the fastest of all
  • very often, numbers that are generated by this method are repeated with the same sequence! For example after 5 iterations I can get: 8, 10, 20, 30, 16. After more clicking (for like 15 seconds) I can get 10, 30, 20 in a row or 30, 20, 10.. I’m not sure, but that’s NOT what I call “random”.

so is there any way to deal with the problem that I’ve described, or is there any other method?

  • 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-06-03T10:23:38+00:00Added an answer on June 3, 2026 at 10:23 am
    textBox4.Text = (2 * rand.Next(min / 2, max / 2)).ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any well-known method for generating random, good looking and yet distinctive colors?
Is there any good documentation on implementing new refactorings in Eclipse? Specifically, I'd like
Is there any good practice for this? I wish I could solve the problem
Is there any good tutorial or code snippet out there on how to use
Are there any good reasons for why you would include JavaScript like this: <script
Are there any good technical solutions for extremely long term archiving of data, for
Are there any good examples of mvc routing wherein every 404 page not found
Are there any good open source frameworks for developing computer system emulators? I am
Is there any good way of truncating text with plain HTML and CSS, so
Are there any good books on the subject worth reading and still up-to-date with

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.