This question already has an answer here:

I need a function that generates a random number from 0 to n for the lottery. I found 2 ways to do that:
1. https://gist.github.com/alexvandesande/259b4ffb581493ec0a1c But miners can influence the number by not publishing a block with an unwanted outcome
2. Use JSON-RPC random.org with oraclize.it But oraclize is centralized service.
So, which is the safest way to generate a random number?

marked as duplicate by eth, Tjaden Hess, Joris Bontje, Afri, Péter Szilágyi Feb 23 '16 at 9:52

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.