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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:01:13+00:00 2026-06-14T00:01:13+00:00

System.Random generator = new Random(DateTime.Now.Millisecond); int[] lotteryNumber = new int[7]; Console.WriteLine(Your lottery numbers: );

  • 0
System.Random generator = new Random(DateTime.Now.Millisecond);
int[] lotteryNumber = new int[7];

Console.WriteLine("Your lottery numbers: ");
for (int i = 0; i<7; i++)
{
    lotteryNumber[i] = generator.Next(1, 37);
    Console.Write("{0} ",lotteryNumber[i]);
}
Console.ReadLine();

I need to make a program that prints 7 lottery numbers, but without duplicates. The code above prints 7 random numbers in the range of (1-37), but duplicates appaer. I need a way to prevent duplicate numbers from appearing.

  • 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-14T00:01:14+00:00Added an answer on June 14, 2026 at 12:01 am

    The simplest approach IMO would be to generate a sequence of all the possible numbers (i.e. 1-37), shuffle the collection, then take the first seven results.

    Searching on Stack Overflow for “Fisher-Yates shuffle C#” will find lots of examples.

    In fact, you could modify the Fisher-Yates shuffle to yield results as you took them, so you could write a method such as:

    var numbers = Enumerable.Range(1, 37).Shuffle().Take(7).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using large random numbers as keys (coming in from another system). Inserts
The following program terminates correctly: import System.Random randomList = mapM (\_->getStdRandom (randomR (0, 50000::Int)))
In C++11 there are a bunch of new Random number generator engines and distribution
I'm attempting to implement a random number generator system; essentially I'm reading in an
I need to generate an array int[] randomNumbers of random numbers with no duplicates.
Possible Duplicates: Random numbers in C# Random number generator not working the way I
This is my homework assignment: Random r = new Random(); public int get100RandomNumber() {
I'm create an air traffic control system, where it generates a random amount of
using System; namespace random { interface IHelper { void HelpMeNow(); } public class Base
How does one turn any random object into a JSON string using Monodroid's System.Json

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.