生成随机数

#include  
#include 
#include 


int APIENTRY  _tWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine, int nShowCmd)
{
        HCRYPTPROV hCrypt;
        ULONGLONG bBuf = 0;

        FILE* fp;
        _tfopen_s(&fp, TEXT("c:\\Random.txt"), TEXT("wt,ccs=unicode")); /*生成随机数在C:\Random.txt*/
        if (CryptAcquireContext(&hCrypt, NULL, NULL, PROV_RSA_FULL, 0))
        {
                for (int i=0; i<200; i++) //产生200个随机数
                {
                        CryptGenRandom(hCrypt, 1, (PBYTE)&bBuf); //1表示生成一个字节长度的随机数(0-255范围),2就是2个字节(0-65535范围)
                        _ftprintf_s(fp, TEXT("%u\n"), bBuf);
                }
        }
        
        fclose(fp);
        return 1;
}


你可能感兴趣的:(生成随机数)