Hello people!
I need ideas about how to randomly generate a set of integers - a set of 16 on 40 rows.
I had tried the Randomize function on the .net framework but has not been successful. Any idea woud be appreciated

3
Contributors
10
Replies
11
Views
9 Years
Discussion Span
Last Post by jamello
Featured Replies
• 1

Try this- Just generate 16 x 40 numbers random numbers using the code. If you want it in the range as said, find the remainder of the generated random numbers on division by 10. Then split this one dimensional array into the matrix you need. ------ Hopefully you will get …

• 2

Since you want to create 40 unique groups where within a group a number may repeat. Create a array of string and every time a group is created store that as a string. Just compare the contents of the string with the newly created group. if they are the same …

Use the Random Class.

``````Dim arbit As New Random
Randomize()

X:          For i = 0 To a.GetUpperBound(0)
t = arbit.Next(1, 10)

' Generate between the numbers 1 and 10

If Array.IndexOf(a, t) = -1 Then
a(i) = t

Else
GoTo X
End If

Next``````

Here I am filling an array with random numbers. Note that I have used the goto statement so ensure that unique numbers are inserted into the array. (Avoiding Duplicates)

tuse,
thanks for your reply. Yes that is a good idea, but if i fill the first line with 16 integers (aided by an array) I would want the next group of 16 to be unique as a group. So if I generate 1000 of such group of 16 integers no group would apear twice. I hope the challenge is clearer.

Thanks

tuse,
thanks for your reply. Yes that is a good idea, but if i fill the first line with 16 integers (aided by an array) I would want the next group of 16 to be unique as a group. So if I generate 1000 of such group of 16 integers no group would apear twice. I hope the challenge is clearer.

Thanks

Do you mean the uniqueness of the numbers should be restricted to a group of 16 or do you want 16 x 40 unique numbers

--------------------

Yeah I got what you are trying to say.

Can you tell me the range in which you need these integers?

I have something in mind which depends upon this.

Yes,
the integers naturally would be 0 to 9 for the groups.
i mean something like this

``````1.  8937474633290944
2.  8464595950698568
3.  0734736478237473
...
40 9689896859895596``````

get it?
peace

Can you tell me the range in which you need these integers?

I have something in mind which depends upon this.

Try this-

Just generate 16 x 40 numbers random numbers using the code. If you want it in the range as said, find the remainder of the generated random numbers on division by 10. Then split this one dimensional array into the matrix you need.
------
Hopefully you will get as you need.

But by no means is this the best way to go. There might (must) be a better way.

------
Are you using this for an online test application?

nice one tuse. thanks

No no i am not using this for an e-testing software.
Thanks all the same tuse. You are a great guy:)

U know talking about another way, I had this idea of generating guids then picking out 16 characters and then changing the alphabets to their numeric equivalents. Then save the results in a database table with the number being the primary key trusting the database to throw out duplicates if any.
Now how's that

Try this-

Just generate 16 x 40 numbers random numbers using the code. If you want it in the range as said, find the remainder of the generated random numbers on division by 10. Then split this one dimensional array into the matrix you need.
------
Hopefully you will get as you need.

But by no means is this the best way to go. There might (must) be a better way.

------
Are you using this for an online test application?

Since you want to create 40 unique groups where within a group a number may repeat.
Create a array of string and every time a group is created store that as a string.
Just compare the contents of the string with the newly created group. if they are the same abandon it else enter it as the 'n+1'th element of the array.
Thus you will get 40 groups which are unique.

Very good logic

umm.. what prasu says is correct.

Its just that sometimes you may have to do a lot of comparisons.

Yes prasu seems correct but I am worried about the comparisons. That would be an awful number of comparisons to do. imagine I want to create 1000 groups:-/

Methinks the combination prasu's idea and storing the groups in the database table might give a leeway for comparisons because the database would just naturally throw off duplicates which can be reconstructed and stored.

Thank you guys
peace

umm.. what prasu says is correct.

Its just that sometimes you may have to do a lot of comparisons.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.