Click here to Skip to main content
15,881,882 members
Home / Discussions / C#
   

C#

 
AnswerRe: Random numbers Pin
Luc Pattyn6-May-11 3:52
sitebuilderLuc Pattyn6-May-11 3:52 
GeneralRe: Random numbers PinPopular
David19876-May-11 3:57
David19876-May-11 3:57 
GeneralRe: Random numbers Pin
PIEBALDconsult6-May-11 16:19
mvePIEBALDconsult6-May-11 16:19 
GeneralRe: Random numbers Pin
David19876-May-11 21:41
David19876-May-11 21:41 
AnswerRe: Random numbers Pin
Orcun Iyigun6-May-11 8:37
Orcun Iyigun6-May-11 8:37 
AnswerRe: Random numbers Pin
Prasanta_Prince6-May-11 15:32
Prasanta_Prince6-May-11 15:32 
GeneralRe: Random numbers Pin
meet_ssr6-May-11 22:30
meet_ssr6-May-11 22:30 
AnswerRe: Random numbers Pin
lampiclobe7-May-11 0:49
lampiclobe7-May-11 0:49 
Hi meet_ssr,
You can construct a List<int> object with incrementing from 0 to n (say 0 to 10: 0,1,2,3,4,5,6,7,8,9); then pop at the index given by random(). Let me show you:
private static void NonRecurrentRandomize(int capacity)
{
    //initialize sample:
    //capacity is your sample size
    List<int> orderedList = new List<int>(capacity);
    for (int i = 0; i < capacity; i++)
    {
        orderedList.Add(i); //0,1,2,3,4,..
    }

    Random r = new Random();
    //Begin process:
    while (orderedList.Count > 0)
    {
        int popIndex = r.Next(0, orderedList.Count);
        //this is the item in turn:
        Console.WriteLine(orderedList[popIndex]);
        orderedList.RemoveAt(popIndex);
    }
}


Hope this can be useful for you. (by the way i tested it in vs 2010)
Cheers.
Ozgur Sonmez.

GeneralRe: Random numbers Pin
meet_ssr8-May-11 20:54
meet_ssr8-May-11 20:54 
AnswerRe: Random numbers Pin
lampiclobe10-May-11 11:56
lampiclobe10-May-11 11:56 
AnswerRe: Random numbers Pin
#realJSOP7-May-11 1:33
mve#realJSOP7-May-11 1:33 
RantRe: Random numbers Pin
lampiclobe7-May-11 12:26
lampiclobe7-May-11 12:26 
GeneralRe: Random numbers Pin
#realJSOP7-May-11 12:47
mve#realJSOP7-May-11 12:47 
GeneralRe: Random numbers Pin
lampiclobe7-May-11 20:45
lampiclobe7-May-11 20:45 
Questionadd and not add button "show data" in to Datagrid in C# ???? Pin
aa_zz6-May-11 0:19
aa_zz6-May-11 0:19 
AnswerRe: add and not add button "show data" in to Datagrid in C# ???? Pin
Ravi Sant6-May-11 1:17
Ravi Sant6-May-11 1:17 
QuestionHow to resolve the XML Error Pin
meeram3955-May-11 22:40
meeram3955-May-11 22:40 
AnswerRe: How to resolve the XML Error Pin
Pete O'Hanlon5-May-11 23:09
mvePete O'Hanlon5-May-11 23:09 
GeneralRe: How to resolve the XML Error Pin
meeram3955-May-11 23:18
meeram3955-May-11 23:18 
GeneralRe: How to resolve the XML Error Pin
Pete O'Hanlon6-May-11 0:13
mvePete O'Hanlon6-May-11 0:13 
AnswerRe: How to resolve the XML Error Pin
Eddy Vluggen6-May-11 0:04
professionalEddy Vluggen6-May-11 0:04 
GeneralRe: How to resolve the XML Error Pin
meeram3956-May-11 0:14
meeram3956-May-11 0:14 
GeneralRe: How to resolve the XML Error Pin
Eddy Vluggen6-May-11 0:36
professionalEddy Vluggen6-May-11 0:36 
GeneralRe: How to resolve the XML Error Pin
meeram3956-May-11 1:21
meeram3956-May-11 1:21 
QuestionHow to format a datetime to display day of week and date? Pin
Goalie355-May-11 10:39
Goalie355-May-11 10:39 

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.