| | |
how do I generate random numbers
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Use the Random Class.
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)
asp.net Syntax (Toggle Plain Text)
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)
My blog on .NET- http://dotnet.tekyt.info
•
•
•
•
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
--------------------
Yeah I got what you are trying to say.
Last edited by tuse; Jul 25th, 2008 at 2:06 pm. Reason: Eureka!
My blog on .NET- http://dotnet.tekyt.info
Can you tell me the range in which you need these integers?
I have something in mind which depends upon this.
I have something in mind which depends upon this.
My blog on .NET- http://dotnet.tekyt.info
Yes,
the integers naturally would be 0 to 9 for the groups.
i mean something like this
get it?
peace
the integers naturally would be 0 to 9 for the groups.
i mean something like this
ASP.NET Syntax (Toggle Plain Text)
1. 8937474633290944 2. 8464595950698568 3. 0734736478237473 ... 40 9689896859895596
peace
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?
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?
Last edited by tuse; Jul 25th, 2008 at 2:43 pm. Reason: Saw the previous post
My blog on .NET- http://dotnet.tekyt.info
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
what's your take?
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
what's your take?
•
•
•
•
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?
Last edited by jamello; Jul 25th, 2008 at 3:22 pm.
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.
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.
umm.. what prasu says is correct.
Its just that sometimes you may have to do a lot of comparisons.
Its just that sometimes you may have to do a lot of comparisons.
My blog on .NET- http://dotnet.tekyt.info
![]() |
Similar Threads
- program to generate random numbers for a given range (C++)
- how to use generate random numbers (Visual Basic 4 / 5 / 6)
- Program will not generate random numbers (C++)
- need help, need to generate 10 random numbers, such that their sum is less than 1 (C)
- Trying to find a better way to generate random numbers in Dev Pascal (Pascal and Delphi)
- generate random question (C)
- random numbers all different??? (C++)
Other Threads in the ASP.NET Forum
- Previous Thread: Online Test Creation
- Next Thread: Please help me asap.
Views: 2822 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 activexcontrol advice ajax asp asp.net beginner bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox child class click compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datalist deadlock deployment development dgv dropdown dropdownmenu dynamic edit embeddingactivexcontrol feedback findcontrol flash flv folder form forms grid gridview homeedition hosting identity iframe iis index javascript jquery languages list maps menu mobile mono mssql multistepregistration nameisnotdeclared novell object objects order problem profile ratings refer rotatepage search security serializesmo.table silverlight smartcard sql ssl tracking treeview typeof update validation vb vb.net view virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopment wizard xml





