Skip to content

Instantly share code, notes, and snippets.

@DiegoQueiroz
Created July 22, 2020 21:39
Show Gist options
  • Save DiegoQueiroz/ccfa852132534eaf3a2ca2ae097fa7e5 to your computer and use it in GitHub Desktop.
Save DiegoQueiroz/ccfa852132534eaf3a2ca2ae097fa7e5 to your computer and use it in GitHub Desktop.
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