Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
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 
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 
I haven't looked at your test, but if you'd like to time this code, have at it. I have no idea if it's any faster or slower, but it seems almost instantaneous to me Of course, every run is going to take a different amount of time because of the random.Next() function. The code below changes the range of random numbers if possible.

C#
HashSet<int> hash   = new HashSet<int>();
Random       random = new Random(DateTime.Now.Millisecond);
int          value  = 0;
int          start  = 1;
int          stop   = 10;
do
{
    try
    {
        value = random.Next(start, stop);
        hash.Add(value);
        if (value == start)
        {
            start++;
        }
        else if (value == stop)
        {
            stop--;
        }
        if (start == stop && hash.Count < 10)
        {
            hash.Add(start);
        }
    }
    catch (Exception)
    {
        // eat the exception
    }
} while (hash.Count < 10);

".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997


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 
AnswerRe: How to format a datetime to display day of week and date? Pin
dbrenth5-May-11 10:51
dbrenth5-May-11 10:51 
AnswerRe: How to format a datetime to display day of week and date? Pin
Luc Pattyn5-May-11 10:51
sitebuilderLuc Pattyn5-May-11 10:51 
AnswerRe: How to format a datetime to display day of week and date? Pin
PIEBALDconsult5-May-11 16:17
mvePIEBALDconsult5-May-11 16:17 
AnswerRe: How to format a datetime to display day of week and date? Pin
Richard MacCutchan5-May-11 21:27
mveRichard MacCutchan5-May-11 21:27 
AnswerRe: How to format a datetime to display day of week and date? Pin
Goalie3511-May-11 5:00
Goalie3511-May-11 5:00 

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.