The second is what I say about being evenly distributed.
The first is easy to solve. Get a result that's sufficiently fine-grained and in the range [0,1). Then scale up by X and round up.
You can add randomness by pushing your number through a cryptographic hash function and treating the result as a binary number in the range [0,1).