943,626 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 5207
  • ASP.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 23rd, 2008
0

how do I generate random numbers

Expand Post »
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
Reputation Points: 215
Solved Threads: 6
Posting Whiz in Training
jamello is offline Offline
219 posts
since Oct 2006
Jul 24th, 2008
0

Re: how do I generate random numbers

Use the Random Class.

asp.net Syntax (Toggle Plain Text)
  1.  
  2.  
  3. Dim arbit As New Random
  4. Randomize()
  5.  
  6. X: For i = 0 To a.GetUpperBound(0)
  7. t = arbit.Next(1, 10)
  8.  
  9. ' Generate between the numbers 1 and 10
  10.  
  11. If Array.IndexOf(a, t) = -1 Then
  12. a(i) = t
  13.  
  14. Else
  15. GoTo X
  16. End If
  17.  
  18. Next
  19.  

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)
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jul 25th, 2008
0

Re: how do I generate random numbers

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
Reputation Points: 215
Solved Threads: 6
Posting Whiz in Training
jamello is offline Offline
219 posts
since Oct 2006
Jul 25th, 2008
0

Re: how do I generate random numbers

Click to Expand / Collapse  Quote originally posted by jamello ...
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.
Last edited by tuse; Jul 25th, 2008 at 2:06 pm. Reason: Eureka!
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jul 25th, 2008
0

Re: how do I generate random numbers

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

I have something in mind which depends upon this.
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jul 25th, 2008
0

Re: how do I generate random numbers

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

ASP.NET Syntax (Toggle Plain Text)
  1. 1. 8937474633290944
  2. 2. 8464595950698568
  3. 3. 0734736478237473
  4. ...
  5. 40 9689896859895596
get it?
peace

Click to Expand / Collapse  Quote originally posted by tuse ...
Can you tell me the range in which you need these integers?

I have something in mind which depends upon this.
Reputation Points: 215
Solved Threads: 6
Posting Whiz in Training
jamello is offline Offline
219 posts
since Oct 2006
Jul 25th, 2008
1

Re: how do I generate random numbers

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 tuse; Jul 25th, 2008 at 2:43 pm. Reason: Saw the previous post
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007
Jul 25th, 2008
0

Re: how do I generate random numbers

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?

Click to Expand / Collapse  Quote originally posted by tuse ...
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.
Reputation Points: 215
Solved Threads: 6
Posting Whiz in Training
jamello is offline Offline
219 posts
since Oct 2006
Jul 25th, 2008
2

Re: how do I generate random numbers

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.
Reputation Points: 13
Solved Threads: 1
Newbie Poster
prasu is offline Offline
11 posts
since Jun 2008
Jul 25th, 2008
0

Re: how do I generate random numbers

umm.. what prasu says is correct.

Its just that sometimes you may have to do a lot of comparisons.
Reputation Points: 32
Solved Threads: 14
Junior Poster
tuse is offline Offline
173 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: free projects in ASP.NET
Next Thread in ASP.NET Forum Timeline: Please help me asap.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC