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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:32:07+00:00 2026-06-06T05:32:07+00:00

Sorry for asking such a vague question, i’m new to using C# / ASP.NET.

  • 0

Sorry for asking such a vague question, i’m new to using C# / ASP.NET. When creating randomly generated questions, and storing the question objects within a list through the use of a for loop the same / duplicate question is showing up when I output the questions. I’ve inspected the list of questions with the debugger, and it shows 10 of the same object.

Server-side C# Used to populate the list of questions:

private void Populate()
{
    __NumberOfQuestions = 10;
    __Questions = new List<Question>(__NumberOfQuestions);

    for (int i = 0; i < __NumberOfQuestions; i++)
    {
        __Questions.Add(new Question());
    }

    QuestionList.DataSource = __Questions;
    QuestionList.DataBind();
}

Question class is avaialable here:
http://pastebin.com/mEArQFHh

ASP Code used to add the questions to the page:

            <asp:Repeater ID="QuestionList" runat="server">
                <ItemTemplate>
                    <tr>
                        <td><%#DataBinder.Eval(Container.DataItem,"__LeftOperand")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem,"__Operator")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem,"__RightOperand")%></td>
                        <td><%#DataBinder.Eval(Container.DataItem,"__Answer")%></td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>

Output:

9
SUBTRACT
6
3
9
SUBTRACT
6
3
9
SUBTRACT
6
3
9
SUBTRACT
6
3
9
SUBTRACT
6
3
9
SUBTRACT
6
3
9
SUBTRACT
6
3
9
SUBTRACT
6
3
9
SUBTRACT
6
3
9
SUBTRACT
6
3

  • 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-06T05:32:09+00:00Added an answer on June 6, 2026 at 5:32 am

    What you’re doing wrong:

    1. You create a new Random object for each Question.
    2. Since you don’t provide an argument to the Random constructor, the default,
      time-based, seed is used. This uses Environment.TickCount (though I don’t think this is documented specifically), so it has millisecond granularity.
    3. Since you construct all of your questions in the same millisecond,
      they’ll use the same seed.
    4. This means that they’ll get the same sequence of random numbers.
    5. This means that you get 10 different questions, but all with the
      same values.

    The simplest way to fix this is to make your Random object static, which means it’s shared by all of the Question objects — or belongs to the Question class, rather than to question instances. This means it’ll only be constructed once, and you’ll get a sensible sequence of random numbers.

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

Sidebar

Related Questions

Sorry for asking a rather n00b question, I am rather new to ASP.NET MVC.
sorry for re-asking, but i have new circumstances. here was my question .net -
First off, I'm sorry for asking such a simple question in such a sophisticated
I am new to Cstring, sorry for asking dumb question, please help. char string[10];
First of all sorry of asking such a dumb question, I am quite a
Sorry for asking what seems like such an obvious question. I have an adapter
Sorry to be asking such similar question again, I am trying to read the
Sorry for asking such a newbie question, I know it makes a few of
sorry for asking dumb questions, java and Android are both new to me ;)
Sorry for asking such a beginner question but I can't figure this out. I

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.