generating a random number within range 0 to n where n can be > RAND_MAX

前端 未结 9 2061
梦毁少年i
梦毁少年i 2021-01-18 08:32

How can I generate a random number within range 0 to n where n can be > RAND_MAX in c,c++?

Thanks.

9条回答
  •  清酒与你
    2021-01-18 08:58

    Random numbers is a very specialized subject that unless you are a maths junky is very easy to get wrong. So I would advice against building a random number from multiple sources you should use a good library.

    I would first look at boost::Random

    If that is not suffecient try of this group sci.crypt.random-numbers Ask the question there they should be able to help.

提交回复
热议问题