Robert Hanson | 10 Feb 2005 18:07

Re: Re: Testing Something that is Random


You ought to be able to find a formula that examines a set of numbers to
determine their randomness.  Perhaps a statistics book, or something in the
discrete mathematics field.  Suppose the fomula yields numbers from 0 to
100, 0 meaning well-ordered and 100 meaning completely random.  Set your
cutoff at some point (85?)  Take your deck, assign each card a number 1 to
52, shuffle it, then use the formula to get a measure of the randomness.
If the formula yields a value more than your cutoff, it performed "well".

I'd write a unit test that did this many times (10, 100 whatever);  if it
yielded a value below the cutoff then the test fails.  If each pass yields
a value above the cutoff, then the test passes.

By tightening up the cutoff (from 85 to 90 to 95, for example) you can
evolve a shuffling algorithm that produces better approximations of a
completely random shuffle.

It is important to note that when you are dealing with a truely random
sequence, ANY sequence is just as likely as any other; thus occasionally
you should see sequences that would be considered "not very random" even if
your shuffling algorithm is optimal.

"SirGilligan" <sirgilligan <at> netscape.net> on 02/10/2005 10:32:29 AM

Please respond to testdrivendevelopment <at> yahoogroups.com

To:    testdrivendevelopment <at> yahoogroups.com
cc:

Subject:    [TDD] Re: Testing Something that is Random

--- In testdrivendevelopment <at> yahoogroups.com, Shane Mingins
<shanemingins <at> y...> wrote:
> Hi
>
> I was justing thinking of TDD a game of black jack and
> was wondering how would you test the 'random-ness' of
> a shuffle?
>
> From a clean deck of cards any 'change' in order could
> be considered a shuffle.  But simply moving a the
> order of a few cards would not be a good shuffle.
>
> Any thoughts or ideas?
>
> Cheers
> Shane
>

Just decided to see what this thread is about. It is too long to read
the ideas out there, and I am sure that there are good ones.

My idea is this: If it is random then it doesn't matter. But, does
random mean "undefined" in a software sense of behavior? That doesn't
seem to be correct thinking but I haven't investigated.

I like to play poker. 5 card draw, low chicago. 5 and 7 card stud.
And of course the popular Texas holdem.

I think it is accepted that a random shuffle of a deck of playing
cards is this: scatter cards face down on table. mix them completely
7 times.

Is it theoritically possible to have the exact same order as the
previous order? Yes. But not likely. But if it did occurr it doesn't
really matter because no one will believe it is happening anyway.

Geoff

Yahoo! Groups Links

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/testdrivendevelopment/

<*> To unsubscribe from this group, send an email to:
    testdrivendevelopment-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Gmane