Implemented parts of the rand algos, and fixed a few errors.