implementation of rand()

后端 未结 11 1470
遥遥无期
遥遥无期 2020-12-01 01:34

I am writing some embedded code in C and need to use the rand() function. Unfortunately, rand() is not supported in the library for the controller. I need a simple implement

11条回答
  •  南笙
    南笙 (楼主)
    2020-12-01 02:27

    I'd take one from the GNU C library, the source is available to browse online.

    http://qa.coreboot.org/docs/libpayload/rand_8c-source.html

    But if you have any concern at all about the quality of the random numbers, you should probably look at more carefully written mathematically libraries. It's a big subject and the standard rand implementations aren't highly thought of by experts.

    Here's another possibility: http://www.boost.org/doc/libs/1_39_0/libs/random/index.html

    (If you find you have too many options, you could always pick one at random.)

提交回复
热议问题