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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:29:29+00:00 2026-05-20T22:29:29+00:00

Hi i want random no. of questions. For that i used random function in

  • 0

Hi
i want random no. of questions. For that i used random function in asp.net but questions gets repeating.
How i can get non repeated questions.
C#.
Thank you.

  • 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-20T22:29:30+00:00Added an answer on May 20, 2026 at 10:29 pm

    The problem with Random is very often the following:

    The following code will very often return a very ‘non-random’ sequence of numbers

            for(int j = 0; j<100; j++)
            {
                Random rnd = new Random();      
                int i = rnd.Next(1, 5);
                Console.WriteLine(i);
            }
    

    Whereas the following will create a more randomized distribution of numbers:

            Random rnd = new Random(); 
            for(int j = 0; j<100; j++)
            {
    
                int i = rnd.Next(1, 5);
                Console.WriteLine(i);
            }
    

    A different approach to generating a random number could be achieved using Linq:

    var randomNumber = Enumerable.Range(1, 10).OrderBy(g => Guid.NewGuid()).First();

    This method first creates a list of numbers (in this example from 1 to 10), and then orders that list by creating a Guid. This shuffles the list so that the First() will be kind of random. I often rely on this method to get a random number instead of using the Random-class.

    UPDATE

    Let’s say you want 10 unique random numbers from a list of 100 random numbers. Using the linq-expression you would do:

    List<int> tenRandomNumbers = Enumerable.Range(1, 100).OrderBy(g => Guid.NewGuid()).Take(10);

    Now you should be able to go through the list of tenRandomNumbers .. They should be unique and random.

    UPDATE 2

    Take a look at this explanation of the .Take(int) method:
    http://msdn.microsoft.com/en-us/vcsharp/aa336757#TakeSimple

    The code above will return a list of 10 numbers selected randomly from a collection of 100 numbers. What you want to do next is simply:

    foreach(int i in tenRandomNumbers){
       // code to fetch your question based on int i
    }
    

    Hope this helps

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

Sidebar

Related Questions

I want to generate random integers between 0-9 (inclusive on both ends), but I
I want to generate random colours which can be attractive in pie charts.I have
I want to generate random numbers from -n to n excluding 0. Can someone
I want to choose random numbers within a range of numbers, but with weighting
I want to get random keys and their respective values from a Map. The
I actually want to generate random password using PHP uniqid() function $randomPassword = uniqid();
When I read some question to write random nuber generator ,I saw that function
If you've used GoToMeeting, that's the type of ID I want. I'd like it
My app is a trivia app that i get questions from the database. There
I want to provide the user with a selection of questions but I want

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.