⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rand.c

📁 WinCE5.0部分核心源码
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
/*++



Module Name:

    rand.c

Abstract:

    Random Generator for DHCPv6 client.



    FrancisD

Environment:

    User Level: Windows

Revision History:


--*/

#include "dhcpv6p.h"
//#include "precomp.h"
//#include "rand.tmh"


DWORD
DhcpV6GenerateRandom(
    PUCHAR pucBuffer,
    ULONG uLength
    )
{
#ifdef UNDER_CE
    if (CeGenRandom(uLength, pucBuffer))
        return STATUS_SUCCESS;
    else
        return STATUS_INVALID_PARAMETER;

#else
    DWORD dwError = 0;
    HCRYPTPROV hCryptProv;


    if (!CryptAcquireContext(
            &hCryptProv,
            NULL,
            NULL,
            PROV_RSA_FULL,
            0))
    {
        dwError = GetLastError();


        if (dwError == NTE_BAD_KEYSET) {
            dwError = 0;
            if (!CryptAcquireContext(
                    &hCryptProv,
                    NULL,
                    NULL,
                    PROV_RSA_FULL,
                    CRYPT_NEWKEYSET))
            {
                dwError = GetLastError();
            }
        }
        BAIL_ON_WIN32_ERROR(dwError);
    }

    if (!CryptGenRandom(
            hCryptProv,
            uLength,
            pucBuffer))
    {
        dwError = GetLastError();
        BAIL_ON_WIN32_ERROR(dwError);
    }

    if (!CryptReleaseContext(hCryptProv,0))
    {
        dwError = GetLastError();
        BAIL_ON_WIN32_ERROR(dwError);
    }

error:
    return dwError;
#endif  // else UNDER_CE

}

//
// Create uniform distribution random number between -0.1 and 0.1
//
DOUBLE
DhcpV6UniformRandom(
    )
{
    DOUBLE dbRand = 0;


    dbRand = rand() / ((RAND_MAX/2) + 1.0);
    dbRand -= 1;
    dbRand = dbRand/10;

    return dbRand;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -