Created
July 22, 2020 21:39
-
-
Save DiegoQueiroz/ccfa852132534eaf3a2ca2ae097fa7e5 to your computer and use it in GitHub Desktop.
This file contains 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
Imports System.Text | |
Imports System.Security.Cryptography | |
Module VBModule | |
Sub Main() | |
Console.WriteLine(GeraDigitosAleatorios(8)) | |
End Sub | |
Function GeraDigitosAleatorios(ByVal tamanho As Integer) As String | |
Dim bytes() As Byte = new Byte(tamanho){} | |
Using rngCsp As New RNGCryptoServiceProvider | |
rngCsp.GetBytes(bytes) | |
End Using | |
Dim sequencia As StringBuilder = new StringBuilder | |
For Each num As Byte In bytes | |
sequencia.Append(num MOD 100) | |
If (sequencia.Length >= tamanho) Then | |
Exit For | |
End If | |
Next | |
return sequencia.ToString(0, tamanho) | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment