RSS RSS feed | Atom Atom feed

Alex's first laptop

Thanks to Alex's grandparents, my parents, Alex received his first laptop as a Christmas present. It was nearly the perfect gift but it needed one additional tweak in order to fit in at our house. Can you guess what that tweak was?

Hint: One of the stickers is new.

Alex and his laptop

CVS obfuscation

A couple days back, I had a really weird thing happen while updating the source code of a project while using IDEA 5(Windows XP). When I would issue the cvs "check directory status" command, it would tell me that the class in a particular package had been removed. After seeing this and knowing that I didn't remove that class, I issued the command again. Now I see that the update put the files back in my workspace like they were new. This went on for a couple hours, acting flakey from time to time. By the end of the day I recreated my workspace and checked everything out from scratch again but the same problem continued to happen. I assumed it was my workspace because our automated build process never had a hiccup. Eventually I went to the cvs repository(Linux) directly to poke around. Low and behold, I saw 2 directories, one using camel case and one using an all lower case naming convention. After looking even further, I noticed that one of the directories was empty but had an Attic directory. The other directory had the mysterious files. Upon inspecting the Attic directory, I saw that files by the same name had been removed from the repository.

In other words, the directory structure looked like this
com/acme/mypackage/Attic/WeirdFile.java,v
com/acme/myPackage/WeirdFile.java,v

My guess is that this weird behavior was happening because I was working on windows where nothing is case sensitive and it couldn't differentiate between these two directories. Bottom line, if you must develop software on inferior operating systems pay attention. Refactoring could cause you to be in this very situation scratching your head.

Rsstroom Reader

This is too funny!

As seen on Weiqi's Blog. I wonder if they will install these when they build our new corporate headquarters

RSStroom Reader
Tags :

How would you write a shuffle algorithm?

As I'm beginning to write my card game application, I've approached the unit test where I need to shuffle the deck. I've implemented it based on Knuth's Shuffle algorithm. My question is, what are some clever ways that other programmers have implemented it?

My current implementation works like this.

  • Put all 52 cards in an array
  • For Loop starting at element 51, working backwards
  • Generate random number between 0 and loop element index
  • Swap current element card with the element at the random index generated in previous step
  • Finish when loop index reaches the zero element.

 

Delima with current implementation

  • Is there a bias with generating a random number between 0 and the loop index? I'm doing so with java.util.Random
  • Would multiple shuffle iterations over the deck solve this?
  • Is it worth refactoring the shuffle algorithm to use the strategy pattern so I can have multiple implementations of shuffle? After all, this is a simple command line game, not Harrah's next killer online gambling app.