다음을 통해 공유


CryptographicBuffer.GenerateRandomNumber 메서드

정의

난수를 만듭니다.

public:
 static unsigned int GenerateRandomNumber();
 static uint32_t GenerateRandomNumber();
public static uint GenerateRandomNumber();
function generateRandomNumber()
Public Shared Function GenerateRandomNumber () As UInteger

반환

UInt32

unsigned int

uint32_t

임의 데이터를 포함하는 정수입니다.

예제


using Windows.Security.Cryptography;
using Windows.Storage.Streams;

namespace Random
{
    sealed partial class GenerateRandomDataApp : Application
    {
        public GenerateRandomDataApp()
        {
            // Initialize the application.
            this.InitializeComponent();

            // Create a buffer that contains random data.
            String strRndHex = this.GenerateRndData();

            // Create a random integer.
            UInt32 uRnd = this.GenerateRndNumber();
        }

        public String GenerateRndData()
        {
            // Define the length, in bytes, of the buffer.
            UInt32 length = 32;

            // Generate random data and copy it to a buffer.
            IBuffer buffer = CryptographicBuffer.GenerateRandom(length);

            // Encode the buffer to a hexadecimal string (for display).
            String hexRnd = CryptographicBuffer.EncodeToHexString(buffer);

            return hexRnd;
        }

        public UInt32 GenerateRndNumber()
        {
            // Generate a random number.
            UInt32 Rnd = CryptographicBuffer.GenerateRandomNumber();

            return Rnd;
        }
    }
}

적용 대상