Why does C++ rand() seem to generate only numbers of the same order of magnitude?

前端 未结 9 2077
孤独总比滥情好
孤独总比滥情好 2021-01-30 01:14

In a small application written in C/C++, I am facing a problem with the rand function and maybe the seed :

I want to produce a sequence of random numbers th

9条回答
  •  旧巷少年郎
    2021-01-30 01:42

    If you want different orders of magnitude, why not simply try pow(2, rand())? Or perhaps choose the order directly as rand(), as Harold suggested?

提交回复
热议问题