Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 21st, 2010, 12:27 PM
Authorized User
 
Join Date: Jun 2008
Posts: 75
Thanks: 15
Thanked 0 Times in 0 Posts
Default Random number Generator between 1 and 4

I need to create a multi dimensional array comprised of random numbers between 1 and 4. The reason why I need a mutidimensional array is because each number needs to be associated with a random letter of F or N. [ F or N are really Indicators or whether I should show the user Feedback on their results in the case of F. Or not show them Feedback in the case of N.] So within this array 2 random numbers will be associated with random F's. And 2 will be associated with random N's. For example the array should look like (1,F 2,F 3,N 4,N) or (3,N 2,F 1,N 4,F). The reason why I need this random array is because during the course of my application being ran 4 times (which represents the numbers) I want to insure that every time N is done 2 times and F is done 2 times. This is all to make sure that each Number 1-4 after 100 times the application is ran has the same amount of F's and N's. I was also wondering if someone knows a way to store how many times the application has been ran in asp.net so that I can recreate another random string after 4 application runs. Thanks for any advice.
 
Old November 21st, 2010, 05:45 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Quote:
This is all to make sure that each Number 1-4 after 100 times the application is ran has the same amount of F's and N's.
Then using a random number generator is *NOT* your answer. A truly random system will *TEND* to get the sane number of occurrences, per value, in 100 iterations. But because the values are truly random, it's very unlikely that you will get *exactly* the same counts. More likely, you'd see something like (94, 102, 97, 107) or similar for the distribution. That's what random *means*.

It *FEELS* to me like what you really want, insted, is a random *ORDERING* of the numbers from 1 to 4 and then a random *ORDERING* of the array (F,F,N,N) and you match up those two random orderings.

But even this won't *guarantee* that you will get the same number of (for example) 1N's as you do 1F's as you do 2N's as you do 2F's, etc. If *THAT* is what you need, then you should instead pre-generate all possible combinations and then simply pick *combinations* randomly.


************

You can store the number of "runs" in a session variable (if the runs are done by one person) or an application variable (if the runs are done via multiple people with multiple browsers). Or, if the runs are done by one person/one browser, just store the run number as a hidden form field.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Number Sequence Generator Peso SQL Server 2000 4 May 11th, 2006 01:36 PM
random number rajuru Beginning PHP 7 December 7th, 2004 10:52 AM
random generator starsailor Javascript 1 December 7th, 2004 12:16 AM
random number isheikh PHP How-To 1 October 25th, 2004 08:43 PM
Random Number Blaise Access 5 August 23rd, 2003 06:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.