CryptographicBuffer.GenerateRandom(UInt32) Méthode
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée une mémoire tampon qui contient des données aléatoires.
public:
static IBuffer ^ GenerateRandom(unsigned int length);
static IBuffer GenerateRandom(uint32_t const& length);
public static IBuffer GenerateRandom(uint length);
function generateRandom(length)
Public Shared Function GenerateRandom (length As UInteger) As IBuffer
- length
-
UInt32
unsigned int
uint32_t
Longueur, en octets, de la mémoire tampon à créer.
Mémoire tampon de sortie qui contient les données aléatoires.
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;
}
}
}
Produit | Versions |
---|---|
WinRT | Build 10240, Build 10586, Build 14383, Build 15063, Build 16299, Build 17134, Build 17763, Build 18362, Build 19041, Build 20348, Build 22000, Build 22621, Build 26100 |