Skip to content

Instantly share code, notes, and snippets.

@jz5
Last active October 14, 2015 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jz5/f86f7b25f232567453ea to your computer and use it in GitHub Desktop.
Save jz5/f86f7b25f232567453ea to your computer and use it in GitHub Desktop.
Imports CoreTweet
Module Module1
Sub Main()
Dim consumerKey = "***"
Dim consumerSecret = "***"
Dim accessToken = "***"
Dim accessSecret = "***"
Dim tokens = CoreTweet.Tokens.Create(consumerKey, consumerSecret, accessToken, accessSecret)
Dim number = GenerateNumber()
tokens.Statuses.Update(New Dictionary(Of String, Object) From {
{"status", number}})
End Sub
Function GenerateNumber() As String
Const digits = "0123456789"
Dim r = New Random
Do
Dim number = ""
For i = 1 To 12
number &= digits(r.Next(0, 10))
Next
If number.Substring(11) <> GetCheckDigit(number.Substring(0, 11)).ToString Then
Return number
End If
Loop
End Function
Function GetCheckDigit(myNumber As String) As Integer
If myNumber.Length <> 11 Then
Throw New ArgumentException
End If
Dim sum = 0
For n = 1 To 11
Dim p = Convert.ToInt32(myNumber.Substring(11 - n, 1))
Dim q = If(n <= 6, n + 1, n - 5)
sum += p * q
Next
Dim r = sum Mod 11
Return If(r <= 1, 0, 11 - r)
End Function
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment