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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:04:09+00:00 2026-05-22T12:04:09+00:00

I use the method to generate unique number but I always get the same

  • 0

I use the method to generate unique number but I always get the same number -2147483648. Even if I stop the program, recompile it and run again I still see the same number.

  public static int GetRandomInt(int length)
    {           
        var min = Math.Pow(10, length - 1);
        var max = Math.Pow(10, length) - 1;
        var random = new Random();
        return random.Next((int)min, (int)max);
    }
  • 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-22T12:04:10+00:00Added an answer on May 22, 2026 at 12:04 pm

    You have three problems with your code.

    1. You should externalize your random variable.
    2. You have a problem with truncation error.
    3. The range between min and max is way to large.

    The first problem is because you may not have enough time to advance the seed when reinitializing your random variable. The second error comes from truncating your (what would b very large) numbers down to ints. Finally, your biggest problem is your range between your min and your max. Consider finding the range between min and max (as defined in your code) with inputs 1->20:

    length  max-min        
    1       8
    2       89
    3       899
    4       8999
    5       89999
    6       899999
    7       8999999
    8       89999999
    9       899999999
    10      8,999,999,999
    11      89999999999
    12      899999999999
    13      8999999999999
    14      89999999999999
    15      899999999999999
    16      9E+15
    17      9E+16
    18      9E+17
    19      9E+18
    

    And keep in mind that the maximum integer is 2,147,483,647, which is passed on any number greater than 9.

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

Sidebar

Related Questions

I making a method that generate a unique string key for some parameters. But
I'd like to use ftplib to upload program-generated data as lists. The nearest method
I need to use method like: DoSomething<(T)>(); But i don't know which Type i
In the first method listed below, the use method, it looks to me like
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I wish to use the method with the following signature: exec(String command, String[] envp,
actually i use this method to show similar words for a search request.. $query
What encryption method does the .NET FormsAuthentication.Encrypt() method use? There's no mention in the
is it possible to use a method of an abstract class? how can i
I'd like to use this method to create user-friendly URL. Because my site is

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.