创建随机数
此示例代码显示了如何在通用 Windows 平台 (UWP) 应用中创建随机数或在加密中使用的缓冲区。
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;
}
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈