Equivalent of /dev/urandom on Windows?

前端 未结 3 846
别那么骄傲
别那么骄傲 2021-01-01 21:50

My application would like to get a random number, preferably with entropy if available, but does not need cryptographic quality, and would like to do ensure that the call do

3条回答
  •  攒了一身酷
    2021-01-01 22:48

    If I need non-blocking behaviour on random numbers, I generally pre-generate n numbers and store them in an in memory variable: ie if I know I will need 30 random numbers per second, takes 3 seconds to compute them (including blocks), then I will pre-generate 300 while the main code is loading, store them in an array or vector and use them at need; whilst using them I generate another one on a separate thread every time I use one up, replacing the utilised random number with the newly generated one and moving on to the next one in the list, that way when I hit the limit (in this case 300) I know when I can simply start again at the start of my array/vector/list and all the random numbers are fresh and will be non-blocking (as they are pre-generated).

    This means you can use any random number generator you like and not worry about blocking behaviour, however it has the expense of utilising more ram, negligible however for the sort of coding I need random numbers for.

    Hope this helps, as I couldn't fit this all into a comment:)

提交回复
热议问题