Is 1.0 a valid output from std::generate_canonical?

后端 未结 3 1779
孤城傲影
孤城傲影 2020-12-01 00:43

I always thought random numbers would lie between zero and one, without 1, i.e. they are numbers from the half-open interval [0,1). The documen

3条回答
  •  清歌不尽
    2020-12-01 01:17

    According to the standard, 1.0 is not valid.

    C++11 §26.5.7.2 Function template generate_canonical

    Each function instantiated from the template described in this section 26.5.7.2 maps the result of one or more invocations of a supplied uniform random number generator g to one member of the specified RealType such that, if the values gi produced by g are uniformly distributed, the instantiation’s results tj , 0 ≤ tj < 1, are distributed as uniformly as possible as specified below.

提交回复
热议问题