Hack Forums
[.NET] [Newb] Random generating 'codes' [Newb] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [Newb] Random generating 'codes' [Newb] (/showthread.php?tid=2927813)



[Newb] Random generating 'codes' [Newb] - Kush - Oct 8, 2012

Hey guys,

I just got into VB.net programming and am literally a noob at this right now. How would I make a button that inputs random numbers and letters into a textbox/label? Like, for a keygen for example.

Thanks in advance C: Will thank the member that helped.


* - Percocet - Oct 8, 2012

If you're trying to make a fake MS point generator, that's pretty fucking stupid.


* - Kush - Oct 8, 2012

(Oct 8, 2012 03:54 PM)๖ۣۜExample Wrote:  If you're trying to make a fake MS point generator, that's pretty fucking stupid.

No, it's a RuneScape PIN generator. It's for my spreading methods.


* - tweety - Oct 8, 2012

PHP Code

<?php 
Public Function Keygenerator(ByVal lenght As Integer) As String
  Dim s 
As New System.Text.StringBuilder("")
  
Dim numbers() As Char = "01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!£$%^&*()_+=-|\¬`,./;'#][<>?:@~}{!£$%^&*()_+=-|\¬`,./;'#][<>?:@~}{".ToCharArray
  
For i As Integer = 1 To lenght

    Dim z 
As Integer = Int(((numbers.Length - 2) - 0 + 1) * Rnd()) + 1
    s
.Append(numbers(z))
  
Next
  
Return s.ToString
    End 
Function 

Param is the length of the key.


* - Kush - Oct 8, 2012

(Oct 8, 2012 03:57 PM)Tweety. Wrote:  
PHP Code

<?php 
Public Function Keygenerator(ByVal lenght As Integer) As String
  Dim s 
As New System.Text.StringBuilder("")
  
Dim numbers() As Char = "01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!£$%^&*()_+=-|\¬`,./;'#][<>?:@~}{!£$%^&*()_+=-|\¬`,./;'#][<>?:@~}{".ToCharArray
  
For i As Integer = 1 To lenght

    Dim z 
As Integer = Int(((numbers.Length - 2) - 0 + 1) * Rnd()) + 1
    s
.Append(numbers(z))
  
Next
  
Return s.ToString
    End 
Function 

Param is the length of the key.

Could you maybe explain the code to me if it doesn't waste your time? I just don't want to be spoon fed and learn nothing along the way C: Thanks for giving it though C:


* - tweety - Oct 8, 2012

(Oct 8, 2012 03:58 PM)Lattens Wrote:  Could you maybe explain the code to me if it doesn't waste your time? I just don't want to be spoon fed and learn nothing along the way C: Thanks for giving it though C:

PHP Code

<?php 
Public Function Keygenerator(ByVal lenght As Integer) As String
  Dim s 
As New System.Text.StringBuilder("") '//String builder that will be appending your text
  Dim numbers() As Char = "01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!£$%^&*()_+=-|\¬`,./;'
#][<>?:@~}{!£$%^&*()_+=-|\¬`,./;'#][<>?:@~}{".ToCharArray '//Characters that you want to be generated. If you want numbers only delete everything apart from numbers
  
For i As Integer = 1 To lenght '//calling a for loop to length to generate a character

    Dim z As Integer = Int(((numbers.Length - 2) - 0 + 1) * Rnd()) + 1 '
//randomizing the character that will be replacted
    
s.Append(numbers(z)) '//appends the single characte
  Next  '
//goes to the next chracater till it meets the length
  
Return s.ToString '//returns the completed string
    End Function 

Learn a lot man. I love people like you.


* - Kush - Oct 8, 2012

(Oct 8, 2012 04:05 PM)Tweety. Wrote:  
PHP Code

<?php 
Public Function Keygenerator(ByVal lenght As Integer) As String
  Dim s 
As New System.Text.StringBuilder("") '//String builder that will be appending your text
  Dim numbers() As Char = "01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!£$%^&*()_+=-|\¬`,./;'
#][<>?:@~}{!£$%^&*()_+=-|\¬`,./;'#][<>?:@~}{".ToCharArray '//Characters that you want to be generated. If you want numbers only delete everything apart from numbers
  
For i As Integer = 1 To lenght '//calling a for loop to length to generate a character

    Dim z As Integer = Int(((numbers.Length - 2) - 0 + 1) * Rnd()) + 1 '
//randomizing the character that will be replacted
    
s.Append(numbers(z)) '//appends the single characte

  Next  '
//goes to the next chracater till it meets the length
  
Return s.ToString '//returns the completed string
    End Function 

Learn a lot man. I love people like you.
Haha, great thanks man. Appreciate your time.