473,398 Members | 2,404 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,398 software developers and data experts.

VB6 Random always the same sequence

104 100+
I have a random function built into my application. It works perfectly. Just one problem it runs the exact random path every time you start the application. Therefore the random selection kicks out the same sequence every time. Is there anything else I can add to the code to overcome that problem? Hope it makes sense.

(Code)
Dim Q
Q = Int((68 * Rnd) + 1)
Text5.Text = Q

Thanks
Aug 30 '07 #1
12 4737
hariharanmca
1,977 1GB
I have a random function built into my application. It works perfectly. Just one problem it runs the exact random path every time you start the application. Therefore the random selection kicks out the same sequence every time. Is there anything else I can add to the code to overcome that problem? Hope it makes sense.

(Code)
Dim Q
Q = Int((68 * Rnd) + 1)
Text5.Text = Q

Thanks
Use one timer control and intrvel to 20 or 50

then use the below code

Expand|Select|Wrap|Line Numbers
  1. Dim q As Double
  2.  
  3. Private Sub Command1_Click()
  4.     Text2.Text = Int((68 * q) + 1)
  5. End Sub
  6.  
  7. Private Sub Timer1_Timer()
  8.     q = Rnd()
  9. End Sub
  10.  
  11.  
I think this will help you.
Aug 30 '07 #2
Wernerh
104 100+
Thanks,

I will give it a go and will let you know

Cheers
Aug 30 '07 #3
Tig201
103 100+
or you could just place the following in your form load
Expand|Select|Wrap|Line Numbers
  1. call randomize
Aug 30 '07 #4
hariharanmca
1,977 1GB
or you could just place the following in your form load
Expand|Select|Wrap|Line Numbers
  1. call randomize
Can you explain with example. Because its returning same sequence.
Aug 30 '07 #5
Wernerh
104 100+
I have used your code as you have suggested and it does not work :-<< It now does not random select at all, it brings up the same selection on every code execution. The list has 68 random selection available. It chose a diff first item than what it use to, but now will not select a second item on execution. Selects same one over and over?
Aug 30 '07 #6
Wernerh
104 100+
Yipee

call randomize Works like a charm!

Thank you
Aug 30 '07 #7
hariharanmca
1,977 1GB
I have used your code as you have suggested and it does not work :-<< It now does not random select at all, it brings up the same selection on every code execution. The list has 68 random selection available. It chose a diff first item than what it use to, but now will not select a second item on execution. Selects same one over and over?
I think you took my older version (later i edited). Just try this. (i missed that rnd method)

Expand|Select|Wrap|Line Numbers
  1. Dim q As Double
  2.  
  3. Private Sub Command1_Click()
  4.     Text2.Text = Int((68 * q) + 1)
  5. End Sub
  6.  
  7. Private Sub Timer1_Timer()
  8.     q = Rnd()
  9. End Sub
if code working fine, then no problem.
Aug 30 '07 #8
Wernerh
104 100+
Thanks for the help, yes the call randomize was all that was needed. Thanks anyway
Aug 30 '07 #9
hariharanmca
1,977 1GB
or you could just place the following in your form load
Expand|Select|Wrap|Line Numbers
  1. call randomize
Yes, this is also working fine. Good.
Aug 30 '07 #10
Killer42
8,435 Expert 8TB
Thanks for the help, yes the call randomize was all that was needed. Thanks anyway
Just a tip - you can drop the Call and just code Randomize.
Aug 31 '07 #11
Tig201
103 100+
Can you explain with example. Because its returning same sequence.
For testing purposes (or at least this is what I was taught) the RND() function goes in a set order so it will give the same numbers every time it is run until you use Randomize.


Just a tip - you can drop the Call and just code Randomize.
Yes, you can but I was taught to use the keyword Call in school and it has become habit.
Aug 31 '07 #12
sgrec7
59
I have a random function built into my application. It works perfectly. Just one problem it runs the exact random path every time you start the application. Therefore the random selection kicks out the same sequence every time. Is there anything else I can add to the code to overcome that problem? Hope it makes sense.

(Code)
Dim Q
Q = Int((68 * Rnd) + 1)
Text5.Text = Q

Thanks
Seriously guys I'm a n00b and I know this stuff.

This is what you want

Expand|Select|Wrap|Line Numbers
  1.  
  2. private sub (what ever)
  3.  
  4. dim Q as integer
  5.  
  6. Randomize (this is the peice that you are missing)
  7.  
  8. Q = int (rnd * 68) +1
  9.  
  10. text5.text = Q
  11.  
  12. end sub
  13.  
  14.  
by the way "randomize" doesn't go blue

so yea this will definitely work

sgrec7
Sep 2 '07 #13

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

Similar topics

23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
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...
25
by: JNY | last post by:
I am using random to generate random numbers, thus: int x,y; for (y = 0;y < 5;y++) { x = random(50); cout << x; }
1
by: steflhermitte | last post by:
Dear cpp-ians, I want to apply a stratified sampling on an image. Following simplified example will explain my problem. The original image I with nrows and ncols is now a vector V of length...
3
by: George Durzi | last post by:
How can I choose a random integer between to given integers? For example, I'd like to pick a random integer between 1 and 3. E.g. 1, 2, or 3 If I do Dim oRandom As New Random(1)...
6
by: DarthBob88 | last post by:
Problem: Getting a random number, an integer. between 0 and 100. I've tried rand() % 100 +1, but that hasn't been very random. Any suggestions? Story: I'm trying to write a simple guessing game....
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...
21
by: chico_yallin | last post by:
I just wana make a random id number based on4 digits-for examples?? Thanks in Advance Ch.Yallin
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.