微软的随机数

    xiaoxiao2024-03-29  13

    typedef ULONG RtlRandomEx( Inout PULONG Seed ); RtlRandomEx* rand = (RtlRandomEx*)GetProcAddress(GetModuleHandle(L"ntdll"), “RtlRandomEx”); ULONG seed = 1; int rands(int a, int b) { return a+ rand(&seed) % (b-a+1); }


    C++

    Copy NTSYSAPI ULONG RtlRandomEx( PULONG Seed ); Parameters Seed

    Unsigned long value from which to generate a random number.

    Return Value RtlRandomEx returns a random number in the range [0…MAXLONG-1].

    Remarks RtlRandomEx returns values that are uniformly distributed over the range from zero to the maximum possible LONG value less 1 if it is called repeatedly with the same Seed.

    The RtlRandomEx function is an improved version of the RtlRandom function. Compared with the RtlRandom function, RtlRandomEx is twice as fast and produces better random numbers since the period of the random numbers generated is comparatively higher.

    最新回复(0)