Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Advanced Random Module

Hey, I am quickly sharing this source with you. Its a module with witch you can generate random chars and strings. But it has some advandced options.

I needed it for a program and thought to share it with the community :)

Here are all the options it got:
  • Letters,Numbers

  • Letters

  • Letters small

  • Letters big

  • Numbers

  • Letters small, numbers

  • Letters big,Numbers

  • Letters,Numbers,Special

  • Numbers,Special

  • Everything



Module
PHP Code

<?php 
Module RandomGenerator

     
''' <summary>
    ''' 
Module created my Maember @ HF. Please, leave credits if you share the code.
    
''' </summary>
    ''' 
<remarks></remarks>     

    Private 
Random As New Random(Environment.TickCount)

    
Friend Enum RandomStringType As Byte
      Alphanumeric 
= 0
      Letters 
= 1
      Lowercase 
= 2
      Uppercase 
= 3
      Numeric 
= 4
      UppercaseNumeric 
= 5
      LowercaseNumeric 
= 6
      AlphanumericSpecial 
= 7
      NumericSpecial 
= 8
      Everything 
= 9
    End 
Enum

    
Friend Function RandomString(ByVal fromL As Integer, ByVal toL As Integer) As String
      
Return GenerateRandom(Random.Next(fromL, toL + 1), RandomStringType.Letters)
    
End Function

    
Friend Function GenerateRandom(ByVal length As Integer, ByVal type As RandomStringType) As String
      Dim r 
As String = ""
      
For i As Integer = 0 To length - 1
      Select 
Case type
            
Case RandomStringType.Everything
            r 
&= RandomEverything()
            Case 
RandomStringType.Letters
            r 
&= RandomLetter()
            Case 
RandomStringType.Uppercase
            r 
&= RandomUpperCase()
            Case 
RandomStringType.Lowercase
            r 
&= RandomLowerCase()
            Case 
RandomStringType.UppercaseNumeric
            Select 
Case RandomNumber(0, 1)
            Case 
0
            r 
&= RandomUpperCase()
            Case 
1
            r 
&= RandomNumber()
            
End Select
            
Case RandomStringType.LowercaseNumeric
            Select 
Case RandomNumber(0, 1)
            Case 
0
            r 
&= RandomLowerCase()
            Case 
1
            r 
&= RandomNumber()
            
End Select
            
Case RandomStringType.Alphanumeric
            Select 
Case RandomNumber(0, 1)
            Case 
0
            r 
&= RandomLetter()
            Case 
1
            r 
&= RandomNumber()
            
End Select
            
Case RandomStringType.AlphanumericSpecial
            Select 
Case RandomNumber(0, 2)
            Case 
0
            r 
&= RandomLetter()
            Case 
1
            r 
&= RandomNumber()
            Case 
2
            r 
&= RandomSpecial()
            
End Select
            
Case RandomStringType.Numeric
            r 
&= RandomNumber()
            Case 
RandomStringType.NumericSpecial
            Select 
Case RandomNumber(0, 1)
            Case 
0
            r 
&= RandomSpecial()
            Case 
1
            r 
&= RandomNumber()
            
End Select
      End Select
      Next
      
Return r
    End 
Function

    
Friend Function GenerateRandom(ByVal fromL As Integer, ByVal toL As Integer, ByVal type As RandomStringType) As String
      
Return GenerateRandom(RandomNumber(fromL, toL), type)
    
End Function

    
Friend Function RandomNumber() As Char
      
Return ChrW(Random.Next(48, 58))
    
End Function

    
Friend Function RandomNumber(ByVal fromL As Integer, ByVal toL As Integer) As Integer
      
Return Random.Next(fromL, toL + 1)
    
End Function

    
Friend Function RandomUpperCase() As Char
      
Return Chr(Random.Next(65, 91))
    
End Function

    
Friend Function RandomLowerCase() As Char
      
Return Chr(Random.Next(97, 123))
    
End Function

    
Friend Function RandomLetter() As Char
      Select 
Case RandomNumber(0, 1)
      Case 
1
            
Return RandomUpperCase()
      Case 
0
            
Return RandomLowerCase()
      
End Select
      
Return Nothing
    End 
Function

    
Friend Function RandomSpecial() As Char
      
Return Chr(Random.Next(33, 64))
    
End Function

    
Friend Function RandomLetterNumericSpecial() As Char
      Select 
Case RandomNumber(0, 2)
      Case 
0
            
Return RandomLetter()
      Case 
1
            
Return RandomNumber()
      Case 
2
            
Return RandomSpecial()
      
End Select
      
Return Nothing
    End 
Function

    
Friend Function RandomEverything() As Char
      Select 
Case RandomNumber(0, 9)
      Case 
0
            
Return RandomLetter()
      Case 
1
            
Return RandomNumber()
      Case 
2
            
Return RandomSpecial()
      Case 
3
            
Return RandomChar(123, 128)
      Case 
4
            
Return RandomChar(130, 140)
      Case 
5
            
Return Chr(142)
      Case 
6
            
Return RandomChar(145, 156)
      Case 
7
            
Return RandomChar(158, 159)
      Case 
8
            
Return RandomChar(161, 172)
      Case 
9
            
Return RandomChar(174, 255)
      
End Select
      
Return Nothing
    End 
Function

    
Friend Function RandomChar(ByVal fromL As Integer, ByVal toL As Integer) As Char
      
Return Chr(RandomNumber(fromL, toL))
    
End Function

End Module 

This is how you use it:

Code
RandomGenerator.GenerateRandom(10, 15, RandomStringType.Everything)

Will generate things like that:
«ÇŸ0d*©5.2
¦Žª-Ÿ‡©Ž‡›
«4™€ŠœŽ}Ž}|„ö

Hope you like it 🎉👍

If you find bugs dont hestiate to write them in the thread 🤝

Peace ✌
[Image: xAhLMBg.png]
Thanks!

I need something like this for a project I'm working on.

As part of a login reset I'm having the system email the user with a random generated string, and storing that string in the database. If the user enters the string from their email, they can reset the password.

This will help a lot with that, much more secure than the standard way of doing things.
Hey, always love to hear good reviews from HQ members. 🤗

Cool that it helped you.

Peace 🤝
[Image: xAhLMBg.png]
Thanks for the post, may actually come in handy!
You should rename the enums to their technical terms like for example:

LettersNumbers
>
Alphanumeric

I think that would be cool,
thanks for the contribution I think most people would find this useful. :P
Skype: happy.cbb
0x38E6A0912657E
Good written source, without errors and doing as supposed. Thank you.
Edit:
Quote:Letters,Numbers
Letters
Letters small
Letters big
Numbers
Letters small, numbers
Letters big,Numbers
Letters,Numbers,Special
Numbers,Special
Everything


Just a tip.
Where "Letters" you can let the the source code user know that you mean Letter "UPPERCASE" and Letter "lowercase" combined.

For the rest I have a cool string generator now.
Regards.
(Nov 21, 2014 07:27 PM)IAmNotHere Wrote:  Good written source, without errors and doing as supposed. Thank you.
Edit:

Just a tip.
Where "Letters" you can let the the source code user know that you mean Letter "UPPERCASE" and Letter "lowercase" combined.

For the rest I have a cool string generator now.
Regards.

"Good written source" coming from a guy who made https://hackforums.net/showthread.php?tid=4539753
Probably I can't beat you, but I have a c++ crypter.
(Nov 21, 2014 05:55 PM)Hiiro Wrote:  You should rename the enums to their technical terms like for example:

LettersNumbers
>
Alphanumeric

I think that would be cool,
thanks for the contribution I think most people would find this useful. :P

Going to do that, I am not an native speaker and didnt know the real terms 🤐 😊
Thank you, for the suggsestion and the positive feedback :)

@Glory2Hypno Thanks for the positive feedback ✌

@IAmNotHere Thanking you too :) Yes, I am going to change that 🤝

Peace to all

Peace 🤝

Edit: Changed the enum names. 🤝
[Image: xAhLMBg.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Shell] by jessman420Feb 22, 2016 05:27 AM 48 6,055 Feb 22, 2016 05:27 AM
Last Post: paramsiddharth
[C] by Trisomy 21Apr 24, 2014 10:19 PM 0 141 Apr 24, 2014 10:19 PM
Last Post: Trisomy 21
[Python] by Hydra_Jun 26, 2013 12:36 AM 4 354 Jun 26, 2013 12:36 AM
Last Post: PigBacon