User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 423,084 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,363 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 857 | Replies: 10 | Solved
Reply
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 202
Reputation: jamello is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

how do I generate random numbers

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2007
Location: Surathkal
Posts: 106
Reputation: tuse is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

  #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.  
  20.  

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  
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 202
Reputation: jamello is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: how do I generate random numbers

  #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  
Join Date: Jul 2007
Location: Surathkal
Posts: 106
Reputation: tuse is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

  #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 1:06 pm. Reason: Eureka!
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote  
Join Date: Jul 2007
Location: Surathkal
Posts: 106
Reputation: tuse is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

  #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  
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 202
Reputation: jamello is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: how do I generate random numbers

  #6  
Jul 25th, 2008
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

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  
Join Date: Jul 2007
Location: Surathkal
Posts: 106
Reputation: tuse is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

  #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 1:43 pm. Reason: Saw the previous post
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote  
Join Date: Oct 2006
Location: somewhere in West-Africa
Posts: 202
Reputation: jamello is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 6
jamello's Avatar
jamello jamello is offline Offline
Posting Whiz in Training

Re: how do I generate random numbers

  #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 2:22 pm.
Reply With Quote  
Join Date: Jun 2008
Posts: 11
Reputation: prasu is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
prasu's Avatar
prasu prasu is offline Offline
Newbie Poster

Re: how do I generate random numbers

  #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  
Join Date: Jul 2007
Location: Surathkal
Posts: 106
Reputation: tuse is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 10
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: how do I generate random numbers

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 5:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC