Help me out here :)

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
I have been presented with this method and asked to give it a name. I've stared at it for an hour or so, and damn it I should know what this is.... but my brain isn't working.

int Foo(int a, int b)
{
return ( new Random().Next() % (b - a + 1)) + a;
}

I figured someone here will bail me out :).
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Are you looking for what it does, or a name for the function? I know what it does, but I'm not sure a specific name comes to mind. It gives a random integer between a and b (inclusive). Maybe RandomIntegerInRange?
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
/slaps forehead

Of course it does :).

Nah, I can come up with the name myself. The problem was that I stared at it too long last night. Guess I didn't think anyone would do that rather than:

Random.Next(a, b);

See, this is what happens when you get intellectually lazy and used to using the api for everything.

Thanks!