codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Home » Visual Basic » Article

VB - Generate an Array of Unique Random Numbers

Article by: Brian Gillham (8/26/2002)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Sponsored by: FindMyHosting - Web Hosting Search
Summary: This function will generate an ARRAY of TRULY random numbers.
Viewed: 84175 times Rating (32 votes): 
 4.3 out of 5
 Rate this Article  Read Comments  Post Comments

VB - Generate an Array of Unique Random Numbers



This function will generate an ARRAY of TRULY random numbers. By default they are unique but this is a parameter which can be parsed. Useful for generating Lottery Numbers etc. I tried searching the net but could not find anything that could do this with the simplicity of this function. See comments within code for full explanation and sample.

Select All Code







CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'VB - Generate an Array of Unique Random Numbers'
Posted by :  Archive Import (Paul Millard) at 14:12 on Friday, October 18, 2002
works very well.
Posted by :  Archive Import (Joan Dav) at 01:41 on Thursday, November 21, 2002
This is great random numbers for vb but i need your help for a problem of mine...
Can you please tell me how to do coding for selecting random name using visual basic. Kind of Lucky Draw game, where a person name is randomly selected.
Posted by :  Archive Import (Reg) at 05:56 on Monday, December 09, 2002
Excellent saved me lots of time typeing boring code....
Posted by :  Archive Import (Bob) at 06:54 on Thursday, December 19, 2002
'TRULY random' you say?
Posted by :  Archive Import (Paul) at 10:24 on Thursday, February 27, 2003
Unfortunately, as pointed out by Bob, there are no truly random numbers - they are derived by calculation, but the code works well.
Posted by :  Archive Import (benson omondi ogogo) at 05:27 on Wednesday, March 05, 2003
random numbers is the best it give opportunities
Posted by :  Archive Import (benson omoni ogogo) at 05:29 on Wednesday, March 05, 2003
it is good
Posted by :  Archive Import (simon) at 12:13 on Wednesday, March 05, 2003
Program works well. Bob or Paul I was wondering if you could explain how the numbers are derived by calculation in the code.

Posted by :  Archive Import (josh) at 20:35 on Thursday, May 01, 2003
i belive that the random number generator in vb uses time and and a certian calculation using that time to get random numbers.

P.S. don't quote me on this
Posted by :  Archive Import (arunb) at 09:03 on Thursday, June 05, 2003
Dear Brian Gillham,

Suber Code, which iam trying to loace from the past. Its working gr8.

Posted by :  Archive Import (Deetch) at 04:32 on Thursday, June 26, 2003
I believe the computer time is used to pick a starting point in a large table of random numbers which is as old as BASIC (maybe even older). If you do not "randomly" change the starting point in the RND-table you'll get the same result every time. I noticed this when I was programming dice for a RISK-game a few years ago.
Posted by :  Archive Import (Crux) at 14:29 on Saturday, July 05, 2003
I thought vb used a formula to derive its random numbers, not selecting them from a table. I think that the formula includes the seed and the number of random numbers already generated. If you notice when you say randomize 1 you get a low number, as the seed increases, so does the first "random" number.
Posted by :  Archive Import (Guille) at 14:59 on Sunday, July 06, 2003
Los números se repiten!
Posted by :  Archive Import (hani) at 17:20 on Sunday, July 13, 2003
can you send the program of visual basic that have a random form
what is the code that random forms because i,m have a create games but the forms in this game is random
plz send and thanks with the web
hani zein - saida-south lebanon
bye
Posted by :  Archive Import (Debabrata Das) at 05:13 on Thursday, September 04, 2003
I appreciate the codes, works fine.
I saved a lot of time.
Thanks a lot
Posted by :  suresh at 08:44 on Monday, September 29, 2003
I needed help in a writing code for generating 6 random numbers 1 to 49 in a label array, when i click the command button. the generated random numbers should be unique, should not repeat. should be dispalyed in a ascending order . can you help me please?

suresh
Posted by :  webit at 10:15 on Monday, November 01, 2004
I needed help in a writing code similar to the one suresh needs for generating random numbers in a label array, when i click the command button. the generated random numbers should be unique, should not repeat. should be dispalyed in a ascending order . can you help me please?


To post comments you need to become a member. If you are already a member, please log in .

 



RELATED ARTICLES
Generate License Keys (such as CD keys on Microsoft software)
by Brian Gillham
This class allows you to generate license keys, such as the CD keys on the case of most Microsoft software
Visual Basic Read and Modify the Registry
by Kenneth Ives
Perform the four basic functions to the Windows registry. Add, change, delete, and query. Allows you to to read registry values, and modify both keys and values.
Communicating with the Database (Using ADO)
by Chaudhary Pradeep K. Roy
Using ADO to get connected with the database.
Generate an Array of Unique Random Numbers
by Brian Gillham
This function will generate an ARRAY of TRULY random numbers.
Beginning Resource Files in Visual Basic
by Kenneth Ives
Have you ever wanted to use graphics, such as icons, bitmaps, cursors, and AVI files? How about sound or even message box text? This can be an enormous amount of overhead. These are all examples of more files to keep track of when you distribute an application, DLL, or OCX. Lets find out how resource files can help....
Visual Basic Compact/Repair Access Database Utility
by Kenneth Ives
This utility will compact and repair the access database you select. It is actually more convenient to use this utility than do the same task with Access, because you don't have to save the database with a different name and then delete the old database when you are done: here, a temporary copy of the database is automatically created and deleted.
Creating a watermark in Excel with VBA
by Kenneth Ives
Adding a watermark to an Excel spreadsheet using VBA.
Generate your own Random Numbers
by Thaha Hussain
This simple program generates random numbers using the basic mathematical methods.
Change Cursor to Hour Glass
by Brian Gillham
A simple script to change the cursor to an hour glass.
Analog Clock
by Thaha Hussain
This program demonstrates Thaha Hussain's Clock Work Formula to paint an Analogue Clock.








Recent Forum Threads
• help - sketch
• Re: Perl Script - File Handling.
• Open a file from website
• Re: to open 5 terminals from one and also execute different commands on each terminal
• read a selected multiple line, those should match some of the values read in the files..
• Help me please
• Empty the contents of a file.
• Month Start, End dates
• show hide problem in dynamic table creation


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008