Random NumX Generator

Danial-Softwares

Random NumX Generator

Random NumX Generator

Hello all. Recently i have created the Random NumX Generator that Generates random numbers based on a given range. Great for randomly choosing things. Need to decide who goes first? Pick a number and let the Random NumX Generator decide for you! Generate as many random numbers as you need at the same time!

I decided to make this app open-source. 😀  Here is the module code (visual basic):


Option Explicit

'//===============================================
'//Coding By Danial Nikbin
'//This function create Random number in special range
'//Count ==> count of number that must created
'//Min ==> Minimume of number that can be created
'//Max ==> Maximume of number that can be created
'//Result() ==> A byref array for put result in it and return to user

Public Function Random_X(ByVal Count As Long, ByVal Min As Long, ByVal Max As Long, ByRef Result() As Long, ByVal Sort_Array As Boolean) As Boolean

Dim i As Long
Dim Top_Array As Long
Dim Rand_Num As Long

Randomize '//Randomize Timer

'//============================
 '//First check that count in range (MAX-MIN)

 If Count > (Max - Min) Then

 Random_X = False
 Exit Function

 Else

 Random_X = True

 End If

 '//============================

Top_Array = 0

ReDim Result(Count - 1) '//Redim Empty Array and Fit it to Count

 For i = LBound(Result) To UBound(Result)

Repeat:

Rand_Num = Rnd() * Max
 Rand_Num = Rand_Num + Max '//Go Number larger than max

 Do While (Rand_Num < Min Or Rand_Num > Max)

 Rand_Num = Rand_Num - (Max - Min) '// IF Rand number is out of range , come it in range

 Loop

 If In_Array_X(Result, Rand_Num, i) = False Then '//IF Not exist then push it into array

 Result(i) = Rand_Num

 Else

 GoTo Repeat

 End If

 Next

 If Sort_Array = True Then Sort Result '//If Sort =True then Sort result array

End Function

'//=======================================
'//This function get a byref array and a num
'//Check the num exist in array

Public Function In_Array_X(ByRef Arr_Name() As Long, ByVal Num As Long, ByVal Top_Arr As Long) As Boolean

Dim i As Long

In_Array_X = False

 If Top_Arr > UBound(Arr_Name) Then Top_Arr = UBound(Arr_Name)

For i = LBound(Arr_Name) To Top_Arr

 If Arr_Name(i) = Num Then

 In_Array_X = True
 Exit For

 End If

 Next

End Function

'//=======================================
'//This Function get a byref array and sort it

Public Sub Sort(ByRef Sort_Arr() As Long)

Dim i As Long, j As Long
Dim Temp As Long

For i = UBound(Sort_Arr) - 1 To LBound(Sort_Arr) Step -1

 For j = 0 To i Step 1

 If Sort_Arr(j) > Sort_Arr(j + 1) Then

 Temp = Sort_Arr(j)
 Sort_Arr(j) = Sort_Arr(j + 1)
 Sort_Arr(j + 1) = Temp

 End If

 Next

 Next

End Sub

And here is the form code (visual basic):


Option Explicit

Private Sub cmdCreate_Click()

Dim i As Long
Dim Result() As Long
Dim IfSuccess As Boolean

List1.Clear

 IfSuccess = Random_X(Val(txtCount.Text), Val(txtMin.Text), Val(txtMax.Text), Result, chkSort.Value)

 If (IfSuccess = True) Then

 For i = LBound(Result) To UBound(Result)

 List1.AddItem Result(i)

 Next

 Else

 MsgBox "Error!"

 End If

End Sub

I hope you enjoy it.

Developer: Danial Nikbin

Our next project: DN Button Maker (HTML)

 

 

14 Comments

  1. Man it was awesome. Thanks for making it open-source 😉

    Reply
  2. I find it hard to understand 😀

    Reply
    • Danial Nikbin

      If it’s hard for you to understand try this simple and useful code. I didn’t use it but i’m sure it will work. Don’t forget to add objects. First You need to add text1.text and command2 in that case when you click on command2 the Randomize number will be shown in text1.text after that When you click on Command1 button the random number will be shown in Text2.Text . Text3.Text and Text4.Text are your given numbers. Note: You must click on command2 to create the Randomize number next enter your 2 numbers finally click on command1.

      Dim a, b, n, d, i As Integer
      Private Sub Command2_Click()
      Randomize
      Text1.Text = Rnd
      End Sub
      
      Private Sub Command1_Click()
      a = Val(Text3.Text)
      b = Val(Text4.Text)
      n = b - a + 1
      d = Val(Text1.Text)
      i = n * d + a
      Text2.Text = i
      End Sub
      
      
      Reply
      • Thanks a lot Danial Nikbin. Now i understand it :D. I love your website and i’m going to add it in my favorite list.❤

        Reply
  3. It is a brilliant app.

    Reply
  4. Nice man. Keep going 😉

    Reply
  5. Everyone loves it whenever people get together and share opinions.
    Great website, keep it up!

    Reply
  6. Hi there! I just would like to offer you a
    big thumbs up for the excellent info you have here on this post.

    I’ll be returning to your web site for more soon.

    Reply
  7. I love what you guys tend to be up too. Such clever work and exposure!
    Keep up the amazing works guys I’ve incorporated you guys to my blogroll.

    Reply
  8. I don’t even understand how I ended up right here, but I thought
    this submit was once good. I don’t realize who you might be however certainly
    you’re going to a famous blogger if you are not already.
    Cheers!

    Reply
  9. Pretty! This was a really wonderful post. Many thanks for providing this info.

    Reply
  10. I see you are sharing interesting posts here. It deserves a wider audience, do you know that in one click you can spread your articles to 703 social sites ? It will bring massive traffic to your site. Just search in google for – k2 seo services – for more info

    Reply
  11. This design is spectacular! You obviously know how to keep a reader entertained.

    Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great job.
    I really enjoyed what you had to say, and more than that, how you presented it.

    Too cool!

    Reply
  12. I’m really enjoying the theme/design of your blog.
    Do you ever run into any browser compatibility issues?
    A few of my blog visitors have complained about my website
    not working correctly in Explorer but looks great in Opera.
    Do you have any tips to help fix this problem?

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *