473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Random Number Generator

I am trying to write a program where I ask the person to input the number of random numbers generated 1-100. Right now I am stuck on one point in particular. How do I write the program to only generate the number from the input box. I know it is probably something like adding value to the code but I am not quite sure.
This is what I have right now and it creates code 1-100. How would I change this to only generating the number instead of actually always creating 100 random numbers.

Expand|Select|Wrap|Line Numbers
  1. Public Sub Random()
  2.     Dim X As Integer, Number As Integer
  3.     Number = InputBox("Enter the number of random numbers to be generated between 1 and 100", "Random Numbers")
  4.     X = 1
  5.     While X <= 100
  6.         Sheet1.Cells(X, 1) = Round(1 + Rnd() * 100, 0)
  7.         X = X + 1
  8.     Wend
  9. End Sub
Sep 27 '07 #1
5 1541
Ali Rizwan
925 512MB
Hello
Ok now use my code

Expand|Select|Wrap|Line Numbers
  1. Dim intPosition As Integer
  2. Randomize
  3. intPosition = Int((1000 - 1 + 1) * Rnd + 1)
  4. lblP.Caption = intPosition
If you write this code in a timer control then it'll generate a random number after a given interval.
Generated numbers between 1-1000

You can also modify by changing 1000 to val(text1) ok
lblP is a label
GOODLUCK
Sep 27 '07 #2
I am trying that but its not working first of all and second of all I am supposed to use a while\wend loop to run the random numbers. I know I can't have yall do the work for me, I just need to know how to fix the code.
Sep 27 '07 #3
Also how do I right the code to average the random numbers. Is it like I know for some part its Average = Round(Sum / Number, 0), but how would I define the sum?
Sep 27 '07 #4
Ok I figured out the random number now I just have problems with the average. I have this so far...
Expand|Select|Wrap|Line Numbers
  1. Average = Round(Sum / Number, 0)
  2.     Range("c1").Value = "Average="
  3.     Range("d1").Value = Average
  4.     For Count = 1 To Number
  5.         If Compare(Sheet1.Cells(Count, 1), Average) = 1 Then
  6.             Sheet1.Cells(Count, 5) = "The Value " & Count & " Above the Average"
  7.         ElseIf Compare(Sheet1.Cells(Count, 1), Average) = 2 Then
  8.             Sheet1.Cells(Count, 5) = "The Value " & Count & " Equals the Average"
  9.         Else
  10.             Sheet1.Cells(Count, 5) = "The Value " & Count & " Below the Average"
  11.         End If
I think it's the sum part that I am having problems with. Also the count is wrong but I don't know what to put value there. I want it to be the number generated in the random number but how do I do that?
Sep 27 '07 #5
Killer42
8,435 Expert 8TB
You shouldn't use sum as a variable name, as Sum() is the name of a function in Excel. (I assume this is Excel - it sure loos like it.)
Sep 28 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Brandon Michael Moore | last post by:
I'm trying to test a web application using a tool written in python. I would like to be able to generate random values to put in fields. I would like to be able to generate random dates (in a...
10
by: Sonoman | last post by:
Hi all: I am trying to write a simple program that simulates asking several persons their birth day and it counts how many persons are asked until two have the same birth day. The problem that I...
3
by: Joe | last post by:
Hi, I have been working on some code that requires a high use of random numbers within. Mostly I either have to either: 1) flip a coin i.e. 0 or 1, or 2) generate a double between 0 and 1. I...
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
5
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible...
104
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a...
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
13
by: porterboy76 | last post by:
If you only use a 32 bit seed for a random number generator, does that mean you can only ever produce a maximum of 2^32 (approx 4 billion) different sequences? What about the Mersenne Twister,...
11
TTCEric
by: TTCEric | last post by:
This will be original. I promise. I cannot get the random number generator to work. I tried seeding with Date.Now.Milliseconds, it still results in the same values. What I have are arrays...
16
by: raylopez99 | last post by:
For the public record. RL public void IterateOne() { Random myRandom = new Random(); //declare Random outside the iteration for (int j = 0; j < Max; j++) {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.