简体   繁体   中英

C11 alternative to rand?

As we know, C++11 got some improvements to random with new additions to <random> as well as some proposals which aim to improve it further. But it seems like C11 has no improvements whatsoever.

Is there a way to avoid using rand() in C11?

It's just a function using some (normally simple) PRNG implementation. You can always "avoid" it and instead provide your own implementation, see eg this question for some alternatives.

BTW, you should think about your intended application. Most rand() implementations will do just fine for eg games, so there's no need to roll out your own. On the other end of the scale, you probably never want to use a PRNG at all for some tasks in cryptography.

There is none, unfortunately. The simplest solution is using the underlying PRNG provided by your system, /dev/urandom for *Unix systems and the CryptoApi under Windows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM