# Random combinations of a group of numbers

Hello,

I need to randomly group the numbers 0 to 90.

example for a group of 1 to 5:

12345
13254
15423
etc.
But I need this for 1 to 90.

Thanks Vbal

###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Dear vbal,
Try the following procedure.

Private Function GetRandomNumber() As Integer
GetRandomNumber = Round(Rnd() * 89) + 1
End Function

I am strongly sure that this procedure would give you what you are looking for.
Meng
0
Author Commented:
thanks,

But this only gives me a random number from 1 to 90.  I need to group all numbers from 1 to 90 in a diferent random order.

1 to 5 coud have these orders as an example:

12345
14532

etc.

the output will be all numbers from 1 to 90 displayed in a new order every time.
0
Commented:
Dear vbal,
How many random number you need to group all of them together ?
In the case of 1-5 , you show that you need 5 random numbers to be grouped together.
Meng
0
Author Commented:
MENG,

For my case I require that all 90 numbers be grouped together.  The 5 is just an example of what I would like for 90 numbers.

0
Commented:
Dear vbal,
Try the following one and give me your comment.
Option Explicit

Private Sub Command1_Click()
Dim strOutput As String
Dim iRnd As Integer
Dim strRnd As String
Dim i As Integer

strOutput = ""
For i = 1 To 90
iRnd = GetRandomNumber

If iRnd < 10 Then
strRnd = "0" & iRnd
Else
strRnd = iRnd
End If

strOutput = strOutput & strRnd
Next i

MsgBox strOutput

End Sub
Private Function GetRandomNumber() As Integer
GetRandomNumber = Round(Rnd() * 89) + 1
End Function

0
Author Commented:
Meng,

No this gives repeat numbers.

Look at it this way if we have the characters A,B,C,D,E
we want to show random orderings of these characters.

Some possible orderings would be:

A,C,B,E,D
or
E,C,D,B,A
or
D,B,C,A,E

I want different combinations of all the integers from 1 to 90.  The combination cannot have repeated integers nor should it be missing any of the integers that exist from 1 to 90.  I just want to randomly order these integers.

Another example for 1 to 5

We have the following integers 1 2 3 4 5
I want to show a new random order of these five integers.

An example of a different order of these five integers could be:

5 4 3 2 1
1 3 2 5 4
etc.

I just want to randomly reorganize the order in which the integers appear.

vbal

0
Commented:
I'm assuming the following:
1- Single digits are represented as single digits, not 0x.
2- All numbers 0-90 are to appear only once.

I'm working in VB.NET.  The following function works.  You'll have to adjust for VB6.  I've included a VB6 random number function for 0-90 inclusive at the end.

--- Code Start ---
Function GenerateRandomString() As String
Dim randomObject As Random = New Random()
Dim randomNumber As Integer
Dim count As Integer = 0
Dim output As String
Dim tally As Boolean() = New Boolean(91) {}

Do While count < 91
randomNumber = randomObject.Next(0, 91)

If tally(randomNumber) = False Then
output &= randomNumber
tally(randomNumber) = True
count += 1
End If

Loop

Console.WriteLine(output)
End Function
--- Code End ---

In VB6,
randomNumber = Int(91 * Rnd())
0
Commented:
In your original post, you say you want numbers 0-90.  In a later post, you say you want numbers 1-90.  Please clarify.
0
Commented:
A couple of corrections to my last post.
- upperbound for a 0-based array should be 90, not 91
- in the VB6 random number generator, don't forget to include Randomize() at start of function
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
brother7,

your assumptions are correct.  However I am having a hard time coding this in vb6.
0
Author Commented:
My vb6 code:

Function GenerateRandomString() As String

Dim count As Integer
Dim output As String
Dim tally(90) As Boolean

Do While count < 90
randomNumber = randomNumber = Int(90 * Rnd())

If tally(randomNumber) = False Then
output = output & randomNumber
tally(randomNumber) = True
count = count + 1
End If

Loop

MsgBox (output)
End Function

I get subscript out of range at: If tally(randomNumber) = False Then
0
Author Commented:
Thanks, brother7.  Got it working.  Just a typo error on my behalf.
vbal
0
Commented:
hi
i think i understood what you want
you need to put a list box Called List1
it can be hidden
and command button called Command1

Private Const FromNumber = 1
Private Const ToNumber = 10

Private Sub Command1_Click()
MN = 1
For i = 1 To ToNumber
MN = MN * i
Next i
For n = 1 To MN
ZZ:
Me.Caption = n
DoEvents
Dim Myarr(FromNumber To ToNumber) As Integer
For i = FromNumber To ToNumber
Myarr(i) = -1
Next i
For i = FromNumber To ToNumber
Dim RN As Integer
RN = GetRandomNumber
Do Until Myarr(RN) = -1
RN = GetRandomNumber
Loop
Myarr(RN) = i

Next i
MyTXT = ""
For i = FromNumber To ToNumber

MyTXT = MyTXT & Myarr(i)
Next i
For i = 0 To List1.ListCount - 1
If List1.List(i) = MyTXT Then
Exit For
End If

Next i
Next n
End Sub

Private Function GetRandomNumber() As Integer

GetRandomNumber = Int((ToNumber * Rnd) + 1)

End Function

hope it works well
0
Commented:
The First works for numbers from 1

Private Sub Command1_Click()
MN = 1
If FromNumber = 0 Then XN = ToNumber + 1 Else XN = ToNumber
.
.
.
.
Private Function GetRandomNumber() As Integer

GetRandomNumber = Int((ToNumber - FromNumber + 1) * Rnd + FromNumber)

End Function
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.