Créer des nombres aléatoires
Cet exemple de code montre comment créer un nombre aléatoire ou une mémoire tampon à utiliser dans le chiffrement dans une application plateforme Windows universelle (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;
}
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour