Add an optional seed parameter

We have to use math/rand instead of crypto/rand if seed
is provided.