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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:12:14+00:00 2026-05-26T19:12:14+00:00

i am trying to generate random number for my mental math quiz game. But

  • 0

i am trying to generate random number for my mental math quiz game. But i think i am doing something wrong.Please help me to correct my code.Please try to include some sort of explanation, why my code is incorrect. Thanks in advance!

 using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;


    namespace MindTraining
    {
        class Program
        {
            static void Main(string[] args)
            {

                Console.WriteLine("Enter the digits of first number ");
                int a=int.Parse(Console.ReadLine());
                Console.WriteLine("Enter the digits of second number");
                int b = int.Parse(Console.ReadLine());

                Random RandomClass = new Random(DateTime.UtcNow.Second);

                int RandomNumber = RandomClass.Next(10^(a-1), 10^a);
                Console.WriteLine(RandomNumber);
    }


    }

}

What i am trying to achieve is , I want user to enter number of digits in number a and number of digits in number b

Then program would generate random number, say user entered 2 for a ,then program have to generate numbers between 0 to 10(Random Number, Every time different)

if user entered 3 for a, then between 10 to 100,

Similar thing for b, and then calculating product.Number should not repeat more than 2 times, during program run time.

Ok, i changed my code to

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace MindTraining
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Enter the digits of first number ");
            int a=int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the digits of second number");
            int b = int.Parse(Console.ReadLine());

            Random RandomClass = new Random(DateTime.UtcNow.Second);
            double num1=Math.Pow(10,a-1);
            double num2=Math.Pow(a,1);
            int num3 = Convert.ToInt32( num1);
            int num4=Convert.ToInt32(num2);

            int RandomNumber = RandomClass.Next(num3,num4);
            Console.WriteLine(RandomNumber);
}}

// But still not getting result, I throws error,

This one worked!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace MindTraining
{
    class Program
    {
        static void Main(string[] args)
        {

            Console.WriteLine("Enter the digits of first number ");
            int a=int.Parse(Console.ReadLine());
            Console.WriteLine("Enter the digits of second number");
            int b = int.Parse(Console.ReadLine());

            Random RandomClass = new Random();
            double num1=Math.Pow(10,(a-1));
            double num2=Math.Pow(10,(a));
            int num3 = Convert.ToInt32( num1);
            int num4=Convert.ToInt32(num2);

            int RandomNumber = RandomClass.Next(num3,num4);
            Console.WriteLine(RandomNumber);
}


}






        }
  • 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-26T19:12:15+00:00Added an answer on May 26, 2026 at 7:12 pm

    is there any reason you want to use a seed value that is so limited? Why not use

    Random RandomClass = new Random();
    

    which takes a default time based seed value for your object?

    Also, use Math.pow(base,exp) to calculate the range for your Random.next() calls as:

    int RandomNumber = RandomClass.Next((int)Math.Pow(10,(a-1)), (int)Math.Pow(10,a));
    

    In your code, the error occurs because,

    double num2=Math.Pow(a,1);
    

    returns a itself. So, your maxvalue in the Random.next() is lower than your minvalue, which is logically incorrect. This is the error, I got from running your code, that is apart from the fact that you are missing a closing brace at the end.

    Also, you must realise that there is no such thing as a perfectly random number generator. All these are pseudo-random generators. They follow the normal distribution of numbers on the number line. So, to say that a number will not be generated more than twice in one execution is not feasible unless you store all the numbers generated and keep checking against them. This should be a last resort, only is case of dire requirements.

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

Sidebar

Related Questions

I am trying to generate a random number, but it should not be a
I am trying to generate a random prime number of type BigInteger, that is
I am trying to generate a random number between two floats (the max is
I am trying to generate a different random number every time my RandomNumber method
I am trying to generate 36 length random number that doest have 0, 1
Im trying to count the number of rows in the table and generate random
I am trying to generate a line of 10000 random number and store it
Possible Duplicate: Java random number with given length I have been trying to generate
I am trying to generate a random enough number quickly. Right Now I am
i'm trying to create a random number generator that will generate number based on

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.