how do I generate random numbers

Thread Solved

Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

how do I generate random numbers

 
0
  #1
Jul 23rd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

 
0
  #2
Jul 24th, 2008
Use the Random Class.

  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)
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: how do I generate random numbers

 
0
  #3
Jul 25th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

 
0
  #4
Jul 25th, 2008
Originally Posted by jamello View Post
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!
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

 
0
  #5
Jul 25th, 2008
Can you tell me the range in which you need these integers?

I have something in mind which depends upon this.
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: how do I generate random numbers

 
0
  #6
Jul 25th, 2008
Yes,
the integers naturally would be 0 to 9 for the groups.
i mean something like this

  1. 1. 8937474633290944
  2. 2. 8464595950698568
  3. 3. 0734736478237473
  4. ...
  5. 40 9689896859895596
get it?
peace

Originally Posted by tuse View Post
Can you tell me the range in which you need these integers?

I have something in mind which depends upon this.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

 
1
  #7
Jul 25th, 2008
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
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 216
Reputation: jamello is an unknown quantity at this point 
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: how do I generate random numbers

 
0
  #8
Jul 25th, 2008
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?

Originally Posted by tuse View Post
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 11
Reputation: prasu is an unknown quantity at this point 
Solved Threads: 1
prasu's Avatar
prasu prasu is offline Offline
Newbie Poster

Re: how do I generate random numbers

 
2
  #9
Jul 25th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

 
0
  #10
Jul 25th, 2008
umm.. what prasu says is correct.

Its just that sometimes you may have to do a lot of comparisons.
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2822 | Replies: 10
Thread Tools Search this Thread



Tag cloud for ASP.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC