Here's thought I had while working on a project for a Visual Basic class.

First off, we were required to create an application that shuffled and dealt a poker hand of 5 cards out of a 52 card deck.
The code we are using to generate the seed for the random number is:

intSavedRandom = DateAndTime.Now.Millisecond 
Dim rand = New Random(intSavedRandom)

For card = 1 To 52
            row = rand.Next(4)
            col = rand.Next(13)

And so on.
I've noticed so far that the most I ever seem to get as far as a seed is a 3 digit number. I assume that goes from either 0 or 1 to 999. My question is, with something like 2.5 million possible poker hands in a 52 card deck, is it ever possible to get all of them? With each seed producing a different hand, it doesn't seem likely. Is there a way to achieve a larger seed?

I've also posted this question in our class forum but I'm not certain how often that gets checked, I figured I had a better chance of getting some feedback here.

First of all, this code is VB.Net, not VB6. Please post in the correct forum.

That said, you are asking the clock for the millisecond count, which will you an integer from 0 to 999; there is your 3-digit number. Because you are using only 1000 unique seeds, your will only generate at most 1000 different poker hands. To get a larger variety of seeds, just use the default constructor for the Random class, that is one without any parameters; this process uses the entire clock value, and not just the milliseconds portion, as the seed.

Dim rand AS New Random  ' Creates Random object using full timer as seed.

Also, your definition of rand makes rand a general type which must be late-bound, meaning that many optimizations that are available for it can not be applied and a few certain features can not be used. Please note the syntax I used. This sets rand specifically as an instance of the Random class, and not of a generic object.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.