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 8092783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:21:38+00:00 2026-06-05T20:21:38+00:00

I have a problem with random number generating in C# I have tried all

  • 0

I have a problem with random number generating in C#

I have tried all the solutions that I’ve found. Most we’re only using the same random object every time which works only each object, not each property.

So I am using this as code for the random numbers:

private static readonly Random random = new Random();
private static readonly object syncLock = new object();

public static int RandomNumber(int min, int max)
{
            lock (syncLock)
            { // synchronize
                return random.Next(min, max);
            }
}

Now I want to call .Next() multiple times in the same method, to generate a random object:

public void StartDuiven()
{
   for (int i = 0; i <= 6; i++)
   {
      var d = new Duif();
      d.Naam = /*NameGenerator.GenRandomFirstName() +" "+ NameGenerator.GenRandomLastName()*/ "Jantje";
      d.GeboorteDatum = DateTime.Now;
      d.Snelheid = Genrator.RandomNumber(0, 4);
      d.Vliegtechniek = Genrator.RandomNumber(0, 4);
      d.Vormpeil = Genrator.RandomNumber(0, 4);
      d.Conditie = Genrator.RandomNumber(0, 4);
      d.Aerodynamica = Genrator.RandomNumber(0, 4);
      d.Intelligentie = Genrator.RandomNumber(0, 4);
      d.Libido = Genrator.RandomNumber(0, 4);
      d.Nachtvliegen = Genrator.RandomNumber(0, 4);
      d.Navigatie = Genrator.RandomNumber(0, 4);
      d.Ervaring = Genrator.RandomNumber(0, 4);
      d.Transfer = false;

      int g = Genrator.RandomNumber(0, 2); // Edited

      if (g == 0)
         d.Geslacht = false;
      else
         d.Geslacht = true;

      AddDuif(d);
   }
}

Every new object I get a different number, but not every time I call .Next() method.

So all the values of the properties become the same for 1 object.

How could I fix this? Why don’t I get a new value on each .Next() call?

Thank you

Bye!

  • 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-05T20:21:39+00:00Added an answer on June 5, 2026 at 8:21 pm

    Random.Next(0, 1) will always return 0. The max value is exclusive.

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

Sidebar

Related Questions

I've found myself with the following problem: I have form with a random number
I am having a problem requesting a random number from random.org using jQuery. When
I have the problem that Tomcat 7 is terribly slow on startup. I found
I have a problem with random and arrays. I have a list empty list
I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the
I have a problem where depending on the result of a random coin flip,
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
i have problem with autorotate on iphone i set up in all classes -
Hello i am having some problems generating random numbers with C# Now i have

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.