Correct a bug in random int selection

randInt should return 0 to max, not 0 to (max-1)
Shuffle some functions between files

Make chain.go look less scary for when the time comes to integrate it
into the key manager.