Create random numbers
This example code shows how to create a random number or buffer for use in cryptography in a Universal Windows Platform (UWP) app.
public string GenerateRandomData()
{
// Define the length, in bytes, of the buffer.
uint 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 randomHex = CryptographicBuffer.EncodeToHexString(buffer);
return randomHex;
}
public uint GenerateRandomNumber()
{
// Generate a random number.
uint random = CryptographicBuffer.GenerateRandomNumber();
return random;
}
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for