Skip to content

Instantly share code, notes, and snippets.

@DiegoQueiroz
Last active July 22, 2020 21:17
Show Gist options
  • Save DiegoQueiroz/7561f3d3c618fde50eabb9691a158f8d to your computer and use it in GitHub Desktop.
Save DiegoQueiroz/7561f3d3c618fde50eabb9691a158f8d to your computer and use it in GitHub Desktop.
Arruma identação
using System;
using System.Text;
using System.Security.Cryptography;
public class Program {
public static void Main() {
Console.WriteLine(GeraDigitosAleatorios(8));
}
public static String GeraDigitosAleatorios(int tamanho) {
if (tamanho <= 0)
throw new ArgumentOutOfRangeException("tamanho");
byte[] bytes = new byte[tamanho];
using(RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider()){
rngCsp.GetBytes(bytes);
}
StringBuilder sequencia = new StringBuilder();
for (int i = 0; i < tamanho; i++) {
sequencia.Append(bytes[i] % 100);
if (sequencia.Length >= tamanho) break;
}
return sequencia.ToString(0, tamanho);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment