Last active
July 22, 2020 21:17
-
-
Save DiegoQueiroz/7561f3d3c618fde50eabb9691a158f8d to your computer and use it in GitHub Desktop.
Arruma identação
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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