Click here to Skip to main content
15,892,059 members
Home / Discussions / C#
   

C#

 
QuestionAvoiding Random() Class generate the same number Pin
gamer112719-Aug-09 3:20
gamer112719-Aug-09 3:20 
AnswerRe: Avoiding Random() Class generate the same number Pin
hairy_hats19-Aug-09 3:23
hairy_hats19-Aug-09 3:23 
GeneralRe: Avoiding Random() Class generate the same number Pin
gamer112719-Aug-09 3:32
gamer112719-Aug-09 3:32 
GeneralRe: Avoiding Random() Class generate the same number Pin
hairy_hats19-Aug-09 3:39
hairy_hats19-Aug-09 3:39 
GeneralRe: Avoiding Random() Class generate the same number Pin
gamer112719-Aug-09 3:45
gamer112719-Aug-09 3:45 
GeneralRe: Avoiding Random() Class generate the same number Pin
Dave Kreskowiak19-Aug-09 4:00
mveDave Kreskowiak19-Aug-09 4:00 
AnswerRe: Avoiding Random() Class generate the same number Pin
Eddy Vluggen19-Aug-09 3:26
professionalEddy Vluggen19-Aug-09 3:26 
AnswerRe: Avoiding Random() Class generate the same number Pin
gamer112719-Aug-09 4:13
gamer112719-Aug-09 4:13 
Ok. I'll post the code that still stores two same numbers into the array.


Here's the code:


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

namespace LotteryGenerator
{
    class RandomNumberGenerator
    {
        Random randomGenerator;
        int[] randomStorage = new int[6];

        public RandomNumberGenerator()
        {
            
        }

        public int RandomGenerator(int randomNumber)
        {
            randomGenerator = new Random();

            for (int a = 0; a < randomStorage.Length; a++)
            {
                for (int aa = 0; aa < 6; aa++)
                {
                   
                    randomNumber = randomGenerator.Next(1, 50);
                    randomStorage[aa] = randomNumber;

                    if (randomStorage[aa] == randomNumber)
                    {
                        randomNumber = randomGenerator.Next(1, 50);
                        randomStorage[aa] = randomNumber;
                        if (Array. )
                        {
                            randomNumber = randomGenerator.Next(1, 50);
                            randomStorage[aa] = randomNumber;
                        }
                    }
                    else
                    {

                    }
                 
                }

                Console.WriteLine("{0}", randomStorage[0]);
          
            }

            return randomNumber;
        }

    }
}



Please leave a comment about what should i do to solve the minor problem. I'm not asking for the codes as i'll be the one to do it. Thanks.
GeneralRe: Avoiding Random() Class generate the same number Pin
PIEBALDconsult19-Aug-09 4:29
mvePIEBALDconsult19-Aug-09 4:29 
GeneralRe: Avoiding Random() Class generate the same number Pin
gamer112719-Aug-09 4:34
gamer112719-Aug-09 4:34 
GeneralRe: Avoiding Random() Class generate the same number Pin
PIEBALDconsult19-Aug-09 7:16
mvePIEBALDconsult19-Aug-09 7:16 
GeneralRe: Avoiding Random() Class generate the same number Pin
Keith Barrow19-Aug-09 4:33
professionalKeith Barrow19-Aug-09 4:33 
GeneralRe: Avoiding Random() Class generate the same number Pin
PIEBALDconsult19-Aug-09 7:17
mvePIEBALDconsult19-Aug-09 7:17 
GeneralRe: Avoiding Random() Class generate the same number Pin
Eddy Vluggen19-Aug-09 4:35
professionalEddy Vluggen19-Aug-09 4:35 
GeneralRe: Avoiding Random() Class generate the same number Pin
Saksida Bojan19-Aug-09 5:49
Saksida Bojan19-Aug-09 5:49 
AnswerRe: Avoiding Random() Class generate the same number Pin
PIEBALDconsult19-Aug-09 7:45
mvePIEBALDconsult19-Aug-09 7:45 
QuestionWhy \r\n? Pin
hairy_hats19-Aug-09 3:00
hairy_hats19-Aug-09 3:00 
AnswerRe: Why \r\n? Pin
Keith Barrow19-Aug-09 3:09
professionalKeith Barrow19-Aug-09 3:09 
GeneralRe: Why \r\n? Pin
hairy_hats19-Aug-09 3:14
hairy_hats19-Aug-09 3:14 
GeneralRe: Why \r\n? Pin
Eddy Vluggen19-Aug-09 3:21
professionalEddy Vluggen19-Aug-09 3:21 
GeneralRe: Why \r\n? Pin
hairy_hats19-Aug-09 3:47
hairy_hats19-Aug-09 3:47 
GeneralRe: Why \r\n? Pin
Dan Neely19-Aug-09 4:33
Dan Neely19-Aug-09 4:33 
AnswerRe: Why \r\n? Pin
PIEBALDconsult19-Aug-09 4:51
mvePIEBALDconsult19-Aug-09 4:51 
AnswerRe: Why \r\n? Pin
Vikram A Punathambekar19-Aug-09 7:13
Vikram A Punathambekar19-Aug-09 7:13 
GeneralRe: Why \r\n? Pin
hairy_hats19-Aug-09 8:17
hairy_hats19-Aug-09 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.