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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:57:42+00:00 2026-05-30T16:57:42+00:00

So I declare a random generator in one of my classes like this static

  • 0

So I declare a random generator in one of my classes like this

static Random random = new Random(DateTime.Now.Millisecond);

and when calling a function in the class even when that function was blank it appeared to block the entire program from running.

static Random random = new Random();

But when I do this it worked as expected?

EDIT with code:

This program is specifically an XNA Game so here is the update function

protected override void Update(GameTime gameTime)
{
    Debug.WriteLine("This happenens");
    EnemyController.generateEnemies();
    Debug.WriteLine("This does not");
}

And here is part of the other class

public static class EnemyController
{
    static Random random = new Random(DateTime.Now.Millisecond);

    public static void generateEnemies()
    {
        Debug.writeLine("This code wont run");
    }
}
  • 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-30T16:57:44+00:00Added an answer on May 30, 2026 at 4:57 pm

    As stated in the MSDN documentation for System.Random for the parameterless constructor:

    Initializes a new instance of the Random class, using a time-dependent default seed value.

    If your instantiation of Random is actually what’s blocking your code, then know that you don’t need to seed it with the time. However, I would look into other possibilities for your code blocking.

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

Sidebar

Related Questions

How can I generate 5 unique random numbers? Now I have something like declare
Declare: LPWSTR** lines= new LPWSTR*[totalLines]; then i set using: lines[totalLines]=&totalText; SetWindowText(totalChat,(LPWSTR)lines[totalLines]); totalLines++; Now I
I declare a static char array, then I pass it to a function. How
Why does Visual Studio declare new classes as private in C#? I almost always
It appear that SQL Server like most other products Random Function really is not
I have a random number generator (RNG) function. -(double) generateRandomNumber { ... do some
declare @d varchar set @d = 'No filter' if (@d like 'No filter') BEGIN
i declare a global variable and use and modify its value in the function.
The intention of following (simplified) code fragment is to return one random row .
With the ThreadStatic attribute I can have a static member of a class 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.