The intrinsic Rnd() function was never meant for crypto purposes, and not even simple statistical purposes. It dates back to an era where large volumes of data weren't being processed anyway.
It is still useful, but mainly for things like generating dummy data and such or simple games.
Here's another decent alternative, though it has been posted many times in Q&A threads:
By varying the "buffer length" and dealing with the sign bit in different ways you can accomodate different needs.Code:'Said to be flawed prior to XP SP3: Private Declare Function RtlGenRandom Lib "AdvAPI32" Alias "SystemFunction036" ( _ ByVal pRandomBuffer As Long, _ ByVal RandomBufferLength As Long) As Long Private Function Rand(ByVal Min As Long, ByVal Max As Long) As Long If RtlGenRandom(VarPtr(Rand), 4) Then Rand = Abs(Rand) Mod (Max - Min + 1) + Min Else Err.Raise 51 'Internal error, for lack of a more specific exception. End If End Function




Reply With Quote