Discussion Forum

Bug: Unrandom Random Generator

When you draw a sample hand, it's not as random as it should be

The last one I just drew is the worst I've seen. The number of cards exactly beside an identical card, not counting basic lands, is astronomical

I have two identical pairs right beside each other in my opening hand and four more pairs in the following draws. If I include basic lands, there's several more.

I draw several more hands and get similar results. Statistically cards are more likely to be beside the same card than any other card or at worse one or two cards away.

Man if I could draw like this at poker, I'd own Las Vegas in a week.

You need to change how it's done or at least run the randomiser three times.

Thorne
Posted 09 December 2011 at 06:20

Permalink

Hello,

In programming terms, getting true random isn't actually quite as simple as just running the good ole RAND() function...

If you really want to know, it's randoming using ORDER BY NEWID(), which as random as MS SQL is going to get, unfortunately. For now it serves its purpose, I think it gives you a reasonably good idea of what a draw could be like, it's never going to be true random.

We'll retouch the process when we rewrite / redesign the sites, which is coming in the next couple of months.

Ian

Edit: Just noticed you posted this in both site areas, which site were you actually referring to?
0
Posted 09 December 2011 at 23:20

Permalink

I will look into this in the upcoming re-write.
0
Posted 10 December 2011 at 17:08

Permalink

I have not worked with SQL yet, so I'm not familiar with its capabilities. But I can imagine a method that reads the randomly generated list and checks for consecutive duplicate values (or however the card index is stored and read) and generate another random value to resort that list segment based on how severe the duplication is. It still wouldn't be true random, but it should solve the problem where sometimes it seems the number generator gets stuck on the same seed resulting in 5-10 lands being clumped together.

It's not the most efficient process, and probably needlessly complicated for the simple purpose of testing a hand. It would be much more feasible to write a method to export deck lists as deck file types for the common MtG emulators (Apprentice, Cockatrice, MWS).
0
Posted 16 January 2012 at 17:08

Permalink

Check this out for unrandom

http://img215.imageshack.us/img215/6840/screenshotyj.jpg
0
Posted 19 February 2012 at 23:49

Permalink

This is still a problem. There are duplicate cards far too often. If you are still using newid() I think it's safe to say that that is not enough. NEWID() is not random it is only unique. Which means that their may be patterns such as sequential elements. So using order by newid() will order arbitrarily not randomly.

The reason I think this is a bit important is that this poor randomization makes it hard to evaluate how a real deck draws. Clusters of cards could be making it worse OR better. So I think we need a proper shuffle.

What you need is the Fisher-Yates shuffle (also called Knuth shuffle). This algorithm is fast and proven to produce a random permutation. If you load the whole deck into a list it is easy to implement and also whatever you are writing the code in may well have a shuffle function that implements this or a similarly good algorithm. So it's not hard to implement a better randomizer.
0
Posted 13 May 2013 at 16:42

Permalink

This post is from the old site, but if this is an issue, I will look into it. No one yet reported anything tho! I don't think we use NEWID anymore, but I'm on my phone ATM so can't confirm the new method :p

Ian
0
Posted 13 May 2013 at 16:47

Permalink

Thanks. Tell me if there is anything I can do. I'm a programmer. So I would be happy to analyse how you did the randomization and recommend changes.

Also:
http://imgs.xkcd.com/comics/im_so_random.png
0
Posted 13 May 2013 at 17:07

Permalink

It's using LINQ to order the list of card objects, something like:

List<Card> shuffledDeck = drawSimulator.OrderBy(a => Guid.NewGuid()).ToList();

I will have a look at the Fisher-Yates shuffle this week, looks easy enough to implement considering I've got a list of objects already :)

Ian
0
Posted 14 May 2013 at 08:30

Permalink

[QUOTE=Ian]It's using LINQ to order the list of card objects, something like:

List<Card> shuffledDeck = drawSimulator.OrderBy(a => Guid.NewGuid()).ToList();

I will have a look at the Fisher-Yates shuffle this week, looks easy enough to implement considering I've got a list of objects already :)

Ian[/QUOTE]

Yea I bet the problem here is that GUIDs are not random only unique.

This may be helpful:
http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
0
Posted 14 May 2013 at 16:15

Permalink

Have implemented Fisher-Yates into the draw simulator now. It looks to be a better spread, but I haven't run enough tests to actually prove it :P

Let me know what you think?
0
Posted 14 May 2013 at 21:30

Permalink

[QUOTE=Ian]Have implemented Fisher-Yates into the draw simulator now. It looks to be a better spread, but I haven't run enough tests to actually prove it :P

Let me know what you think?[/QUOTE]

It is definitely a lot better.

However I then got this "next 20 cards":
Island,Island,Diabolic Edict,Diabolic Edict,Diabolic Edict,Swamp,Dimir Guildgate,Sage's Row Denizen,Sage's Row Denizen,Dream Twist,Psychic Strike,Psychic Strike,Drowner Initiate,Dimir Guildgate,Crypt Incursion,Barren Moor,Doom Blade,Doom Blade,Paranoid Delusions,Paranoid Delusions

While this is not impossible it's very VERY unlikely. I cannot think of an obvious thing that would cause this. Other than a weird case like some of your load balanced servers running the old version and some running the new version. And I don't even know if you have load balancing.

Overall I think it's fixed. I am occationally seeing triples of the same card in the a row in the "next 20", but I don't know how low the probability of that is, so I cannot say if that is a bad sign or not.

BTW, Thanks a LOT for your prompt responses. I'm impressed really.
0
Posted 14 May 2013 at 22:00

Permalink

We do use Cloudflare, so it could be showing an old cached version. I have actually forgot to flush the cache from the control panel, but i'll leave that for the minute, it won't take long to update.

I'm seeing some doubles in the next twenty, but no triples yet. It's using the same shuffled list, but one alteration I could do is actually cleanse the list as it prints the items out. At the minute I'm using list.Take(handSize) then for the next 20, I'm using list.Skip(handSize).Take(20), so maybe that's not as foolproof as I hoped.

I'll have a closer look this week, bed for now, 11pm here ! :]

Also, thanks :P I should also thank you for pointing this flaw out; it's guys like you who help US out by giving feedback :)

Cheers
0
Posted 14 May 2013 at 22:10

Permalink

This is cool! I go on holiday and good stuff happens, I should go away more often! ;)

Thanks for the suggestion and thanks Ian for implementing it! :)
0
Posted 15 May 2013 at 16:01

Permalink