Concern about Randomness of Shuffles

Bug reports, feature suggestions etc...

Moderators: Programmer, WebWeaver, WillowsHeart

Greg the Yeti
Major Contributor
Major Contributor
Posts: 196
Joined: Tue 01 May, 2007 3:11 pm

Concern about Randomness of Shuffles

Post by Greg the Yeti »

Hi,
I've been using a couple of Decks to choose my lottery ticket for a while now and have noticed something which does concern me with regard to the randomness of the shuffle.

How am I using it?

1) I start with a "New Random Deck" (Ctrl+Shift+N), but to increase random factors and include a personal factor...
2) I follow that with a "Seeded Shuffle" (Ctrl+Shift+S) - and to maximize "personalization"
3) I've been drawing the cards one at a time with a Space Bar Press. Allowing at least 4 or 5 seconds before the first press and trying to keep pauses between presses random.

Now that OUGHT to be Random!!!

However I've been noticing more "Consecutive Numbers" than I would expect. Sure in a random draw one should expect Consecutive Numbers sometimes, but I'm getting at least two consecutive numbers virtually every time. I'm suspicious!...

I've also noticed more groups of very close numbers, so that quite often I'm getting 2, 3 or even four numbers in a decade. That also strikes me as suspiciously high!

Ok in a bad instance I simply gather and do the Seeded Shuffle again with a number added to the "Seed" to make it different. Sometimes when I'm feeling particularly suspicious I'll do a New Random Deck first...

I hoped you could think about it, given your better knowledge of what's going on in those processes. I also would like more information about what is going on...

It strikes me that it is most likely to be coming from the Seeded Shuffle stage?

Am I right in thiking that what actually takes place is that cards are successively "Swapped"? In Pairs?
Are ALL the cards swapped by any one specific Seeded Shuffle? Or will some cards be left in "original" places, regardless of how long you wait?

Yes - I know how difficult "Random" is on a computer and yes I have read most of what's on the forum about Shuffling, I just want to know more....

Regards Greg the Yeti

Disclaimer:- I also know that I can't sue you for not having won the jackpot yet!!! Damn!
User avatar
Programmer
Major Contributor
Major Contributor
Posts: 1725
Joined: Sat 01 Jan, 2005 12:00 am
Location: Spain
Contact:

Re: Concern about Randomness of Shuffles

Post by Programmer »

Either of the first two steps alone will produce a random deck. The first method it is not a shuffled deck, it is put together in initially random positions based on the stored movements of the mouse. The second one is a shuffle but is based on a cryptographic random number class that uses all kinds of physical factors (such as the temperature of the processor etc) to arrive at a truly unpredictable result.

As you say, I think this is just to do with the nature of random patterns. A pattern that goes heads tails heads tails heads tails is not random at all, actually it is highly organized. Random patterns are clumpy, and the clumps themselves come in clumps and so do the clumps of clumps.
Greg the Yeti
Major Contributor
Major Contributor
Posts: 196
Joined: Tue 01 May, 2007 3:11 pm

Re: Concern about Randomness of Shuffles

Post by Greg the Yeti »

Hi Richard,
sorry I've not been around in Orphal Space for quite a while - an Emotional Trauma and discovering I had got Cancer from radon gas in my cave being two major factors!

A third factor was not being happy with the randomness of shuffles in Orphalese. I'm sorry, you're answer here simply gave no re-assurance whatever.

I did "A Level" maths and within that studied some Statistics. No, I'm not an expert, but I do know more than most..

I know that "Hunches" and "Having a Nose for the Truth" are things which Newspaper editors dissalow, but I have a VERY strong "Nose" that the shuffles in Orphalese are NOT as random as you think.

Given that your reply had not re-assured me, I regressed to former methods. For my favourite "Spirit Tokens of the Ling Qi Jing" I have a Bread Bin specially modified to allow throws of the real Tokens without making a huge racket. For my lottery tickets I have created a much larger throwing area with a Pet Pooping Tray and a small carpet. For I ching it's nice anyway to use the real Yarrow stalks from time to time. For Tarot one can use the cards themselves.

Using these, entirely non PC based methods, I am now getting random results which have the "Seal of Authenticity" about them. Yes there is some "Clumpiness" as is going to be the case with anything which is truly random, however there is no "Predictability about the Clumpiness", which is what I had come to see in what Orphalese was producing.

This has been a major factor in simply not using Orphalese for quite some time.

I have a similar "Hunch" that the problem lies in the "New Random Deck" and specifically I think that it might have to do with the way that the "Cryptographic Random Number Class" is applied in Orphalese. I note that it is limited to a certain number of cards. My "Hunch" suggests that it is these limits themselves which are introducing the problem.

Hey, I know you've got limited time and that you "wasted" some time last year on the SVG graphics! Sorry again about that. It's a shame that that can't work better....
But if you have time, it would be worth doing a test on Orphalese's suffling, especially that "New Random Deck". I'm CONVINCED it isn't random!

I'm sorry not to be able to help with a long detailed test "Crunch". I've also got an RSI injury, which precludes me doing that much keyboard/mouse crunching at the moment! Once again - sorry - otherwise I probably would want to help in that regard, to prove the case...

Regards Greg
And sorry in advance for being a pain!
User avatar
Programmer
Major Contributor
Major Contributor
Posts: 1725
Joined: Sat 01 Jan, 2005 12:00 am
Location: Spain
Contact:

Re: Concern about Randomness of Shuffles

Post by Programmer »

Hi Greg,

It is really good to hear from you. I am sorry to hear about your health issues but I am glad it sounds like you are getting on top of them.

The physical methods of doing a shuffle that you mention certainly sounds very unpredictable, and obviously there is no way the program can hope to compete with the reassuring tactile qualities of things like pet pooping trays. Actually you have caught me at a good moment to bring this up because I am working on the beta of version 10 right now, and hoping to have something ready for wider testing in the next few weeks. So I should be able to incorporate some tests of both methods into the beta and then hide them or take them out in the full release. I agree with you that if there is anything slewing the result it is more likely to be with the New Random Deck. Although it is supposedly based on something properly random (mouse movements) it is something I programmed from scratch so there could be something wrong with my methodology. I will program something which runs in the background capturing all the data and keeps a tally of the frequency of each result. I appreciate the RSI probably won't let you do much with that but I will put some time in on it myself and see how even the results are looking and maybe some other users will get interested and have a go too.

BTW I have managed to incorporate a few of the things you requested last year, such as letting the user associate decks with subsets of cards, so you can easily have say a majors only and a full deck without having to have duplicate sets of images on your hard drive. I've also programmed spreads and readings with multiple decks (and subsets) so it allows for quite a lot of complexity there. That meant quite a few new changes to different card dealing scenarios so I haven't been able to include that idea of dealing a spread one card at a time, at least this time round - I don't want to do too many changes at once affecting the same thing. But I did find a nice way of showing the total cards in each deck - I have that on the title bar of the background window now, so it will say for example like "Traditional Tarot (Principal Deck) (41/78)" meaning 41 out of 78 cards are left in the deck. There are also lots of other nice new features which we hadn't thought of last year. Linda (a.k.a Purple Scorp), who has stepped forward to set up the Offical Help Website, has come up with a whole load of great suggestions, actually too many to get into this version but as you know that is always the way.

Anway I will post back on this thread when I have something ready to download, hopefully it shouldn't be too long now.

Cheers
Richard
Greg the Yeti
Major Contributor
Major Contributor
Posts: 196
Joined: Tue 01 May, 2007 3:11 pm

Re: Concern about Randomness of Shuffles

Post by Greg the Yeti »

Thanks for that reply.

That idea of putting in an "Auto Store" for shuffle data sounds like it will be a real boon for randomness testing!
I hope you might make that available for users like me and not just for yourself?

Just a hint, from my experience it is easier to see what's going on when using a deck of numbers rather than a traditional Tarot Deck. My experience that the Shuffles wern't random came largely from using those Lottery Decks. I think the mind is more "clued into" noticing structures among numbers rather than among the Majors and Minors?

It also looks like I MUST upgrade to that new version that I downloaded the other day, just to get up to date with all the changes you've made. Will do!

Regards Greg

Oh - with regard to that "Pet Pooping Tray", it proved so popular with one of my dogs - to sleep in, with that comfy carpet, that I had to allow her to have it and buy a new one and line it this time with some Tent Ground Liner, which is a little less inviting to sleep in!...
User avatar
Programmer
Major Contributor
Major Contributor
Posts: 1725
Joined: Sat 01 Jan, 2005 12:00 am
Location: Spain
Contact:

Re: Concern about Randomness of Shuffles

Post by Programmer »

Well Greg, I built that tool into the beta version and the first thing I have to say is you were right, there was a definite weighting towards certain numbers. Specifically the number zero came up with a lot more frequency than any of the others, and there were spikes on all the multiples of ten. The result of that would have been that these cards would always have tended to be found towards the front of the deck. I am referring here to the "New Random Deck" feature, not the regular shuffle. In the new version by the way this has been renamed "New Random Sort" and you can find it on the Sort Menu (the previous wording made it sound too much like the program would launch a deck chosen at random from your deck collection).

The old methodology which gave the bad results was that after any mouse move event I would divide the X co-ordinate by the Y co-ordinate and take the digits in the 6th and 7th decimal positions and that would be the card index chosen. The trouble is there were relatively more results like 0.2345600000 or 0.200000000 than ones not trailing into zeros like 0.1254126874 or whatever.

The new method involves taking three numbers: the result of multiplying the X and Y co-ordinates, the time lapse in milliseconds since the last mousemove event, and a new pseudorandom number generated by .NET's built in CryptographicRandom class. I am adding these three numbers together and the index is the remainder after dividing this new number by a hundred.

The way you can test the results for yourself is by going into the Options form and on the first tab you will see a button marked "Test Randomness". This button is only going to be there in the beta version, later I plan to take it out. When you press this you get a form with two dropdown options.

MousecapDebug.xml: This stores all the numbers generated by your mouse movements using the method described above. I have had it activated for about a week while I was debugging beta 10.0 and the results look pretty good, people can try it in the beta and tell me if they disagree.

ShuffleDebug.xml: This is a simulation of shuffling the deck that runs on a timer (I tried to link it to actually shuffling the deck but it had too much impact on performance. The principal is exactly the same anyway). This doesn't really give any surprises. You can let it go all night and it produces a predictably even set of results over time. I would be surprised if it was any other way because this class is designed by Microsoft to generate very high quality pseudo random numbers suitable for using in professional cryptography.

Hope the results set your mind at rest, otherwise I can still go back and tinker a bit with it before the final release.
Greg the Yeti
Major Contributor
Major Contributor
Posts: 196
Joined: Tue 01 May, 2007 3:11 pm

Re: Concern about Randomness of Shuffles

Post by Greg the Yeti »

Hi Richard, thanks for that!
unfortunately the Beta wasn't there the last time I checked and this time I tried to use the Deck Share and it alerted me to the new full version 10.0.1.1, which I duly installed. So I've not experimented with the Beta. Sorry.

However I've found the MouseCapData.xml manually and will see if I can work out from that what's going on...

It looks to me just like four different "sorts" of the numbers 1 to 99.
Suspiciously the four that I'm looking at ALL have 98 and 99 as the last two numbers, while other numbers look possibly random. If this means what I think it means then perhaps you might need to go back to the drawing board????

The other one ShuffleDebug.xml does not appeaar to be there. So I might need to install the Beta on my spare Window Partition to see if it bears up to your approval rating for the raw .NET Cryptographic Class.
I must say that my faith in Microsoft to do with security/cryptography is not high!!!! As far as I can see they ALWAYS build backdoors for Government and Advertisers to be able to get in... Hence the unending security patches - Basically you can't create backdoors that the hackers wont find! Windows has never been intended to be secure! Lack of security is a deliberately engineered, essential feature of Windows!

I WILL experiment with the "New Random Sort" feature to see if it "feels" right and properly random. Who knows - if it feels right I might even be persuaded to use it for real "at the coal face"!
However my comments above about numbers 98 and 99 do not bode well...

I will let you know...
Regards Greg

Note:- As evidence of what I said above I've copied the MouseCapData.xml file but find that I'm not allowed to attach it here, even if I change the file extension to txt or jpg... drat!
If you want it to confirm what I've said I can e-mail it.
I will even do a couple more copies of that file to see if it's the same (with 98 and 99) every time.
- - -
I did six "New Random Sorts" to use up all available slots and now find that the xml file is blank.
I looked to see if the option to do Random Sorts was somehow now turned off but there seems to be no option for that - its now an always on option?
So I don't know what's going on with that intial MouseCapData.xml file????
User avatar
Programmer
Major Contributor
Major Contributor
Posts: 1725
Joined: Sat 01 Jan, 2005 12:00 am
Location: Spain
Contact:

Re: Concern about Randomness of Shuffles

Post by Programmer »

Hi Greg,

There is no mystery really, I made it so the code which debugs and produces the mouse cap file and shows the data in the program is only activated when it is a beta (i.e. the third number of the full version number is 0), that way I knew it would turn off of its own accord when I published the new version in case I forgot. I am going to bring out a new version at the weekend and I will make it so all that debug data is activated even when it is not a beta, but only for the two of us based on the registration data which the program knows how to read off.

My experience was a bit like yours in that when I first started debugging the program was clocking up lots of 98's and 99's, but then after a couple of weeks it all seemed random. I am guessing you did what I did which is move the mouse back and forwards in a short arc to generate the numbers. When I started just letting the program record the results that occurred during normal usage that skew went away. Anyway, from the weekend you will be able to try it for yourself without having to read the XML file manually.

Cheers
Greg the Yeti
Major Contributor
Major Contributor
Posts: 196
Joined: Tue 01 May, 2007 3:11 pm

Re: Concern about Randomness of Shuffles

Post by Greg the Yeti »

Hi Richard,
and WOW! - my own super duper version of Orphalese!!
With that due out at the weekend, I won't bother downloading and installing the Beta on my spare partition.

Presumably our reg data won't be in "plain text" but encrypted with/like the exe file?

This will be most intesting. I can't wait to get my mits on it!

Regards Greg
Greg the Yeti
Major Contributor
Major Contributor
Posts: 196
Joined: Tue 01 May, 2007 3:11 pm

Re: Concern about Randomness of Shuffles

Post by Greg the Yeti »

Hi Richard,
since you went to the trouble to set up this tool to test randomness, which you've said you're not sharing with all Orphalese users, I reckoned you wanted me to report back and share with other users what I thought? I hope so. Here is what I found...

MouseCapData.xml
You now have five sets of random data not the previous four.
Just looking at them, the previous error which was cropping up of 98 & 99 always occupying the last two spots was now definitely gone!
As far as I can see by eye, the results LOOK random!

MouseCapDebug.xml
Doesn't start a "Simulation", so I'm not quite sure what's what here?
The nubers aren't changing as far as I can see. They do go up to include all 100 "Slots". If the results displayed here are the results of "actual" Random data used by the program, they look fairly good and possibly quite random.
Highest 67
Lowest 36
That looks "Within the Limits" of being random to me...

ShuffleDebug.xml
Does a live test with a Tarot Sized Pack of 78 Cards

Test 1
129 Lowest
166 Highest of most
182 Single highest #72 Way in the Lead!
I had at first had the mouse fairly steady and 72 came out really high. As the test went on I became aware that this might be an issue so I was moving the mouse around "randomly" and other numbers seemed to be "gaining up" on #72.

Starting a simulation again did not start from zero, but added to the past test

Test 2
I went onto the Orphalese Forum,where I was already logged in and played around in the User Control Panel for a while, seeing if I wanted to change anything. I decided to share my birthday and year. I did this to try to give the computer some "Random Mouse Movement"!

334 the higest ~(and no longer #72)
268 the lowest
A fairly even spread by now!

- - -

It would be nice to have a log of how many simulated spreads have been done. Yes I could count up all the results and divide by 78, but the tool doesn't let me copy the column, to then get excell to add them up and divide - damn!

It would also be nice if the tool automatically showed you the higest and lowest result - and perhaps average and standard deviation???
Sorry Richard, somebody had to say that so I thought it might as well be me?

It would be nice if one could erase the previous test and start again.

Overall Very Pretty and extremely "Cool"!
Thanks for the opportunity to see into the workings a bit more and to share the results on the Forum.

Regards Greg

Needless to say I'm gonna play with this cool "random test tool" a good few more times yet, so please don't remove it! (How come I'm thinking of Jason Statham??)

Edit:-
If that right hand column was "copy-able" then I could paste the data into excel and get that to do all the statistical analysis I wanted (or knew how to do!!!)
Post Reply