473,614 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access random number question (Not random at all)

AccessQuestion
13 New Member
So just a quick question; more out of curiosity than anything. I have a form in which I pop a random number into a text box. Eventually that number will be placed by a user using a scale, but I wanted to simulate that now. Anyway, I used this code:

Expand|Select|Wrap|Line Numbers
  1. MyWeight = Int(1000 * Rnd())
  2.  
I assumed that will give me a random number, however EVERY time I launch my form the random numbers are the same. First 'random number' is always 705, followed by 533, etc. What gives with that??? Has anyone run into that before???
Jun 24 '10 #1
3 4424
OldBirdman
675 Contributor
From Access Help for RND:
For any given initial seed, the same number sequence is generated because each successive call to the Rnd function uses the previous number as a seed for the next number in the sequence.

Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.

To produce random integers in a given range, use this formula:

Expand|Select|Wrap|Line Numbers
  1. Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
Also for RANDOMIZE
Randomize uses number to initialize the Rnd function's random-number generator, giving it a new seed value. If you omit number, the value returned by the system timer is used as the new seed value.

If Randomize is not used, the Rnd function (with no arguments) uses the same number as a seed the first time it is called, and thereafter uses the last generated number as a seed value.

Expand|Select|Wrap|Line Numbers
  1. Randomize [number]
Jun 24 '10 #2
Oralloy
988 Recognized Expert Contributor
Looking at the Access 2007 documentation on Rnd(), you will find that it is a pseudo random number generator, and there are four different calling conventions.

In addition there is a specific note about seeding the random number generator:
Before calling Rnd, use the Randomize statement without an argument to initialize the random-number generator with a seed based on the system timer.
Jun 24 '10 #3
AccessQuestion
13 New Member
Ok, thanks! I completely get it now.
Jul 2 '10 #4

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

Similar topics

25
2967
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; }
4
2693
by: Jack | last post by:
I have two files: sort_comparison.c++ my_sort.h sort_comparison.c++ calls this code in my_sort.h: void my_sort::fillArray(int arr,int n) { // const int random_number_range=1000000;
1
3854
by: mrkselm | last post by:
Hi, I am stuck with a problem in MS Access which does not occur in SQL Server and I have been banging my head against the wall for a couple of days now trying to resolve it. Namely, when I execute the following query in Access not all records that fit the condition are returned, and when I run this same query in SQL Server all the records I want are retrieved. The query is:
7
2134
mshmyob
by: mshmyob | last post by:
I know how to create a random number using lower and upper limits but am curious if you can generate a random number from a set of specific numbers. For instance I want to randomly pick either 1, 3, 7, or 9 only. Right now I just put the random number generator with a lower limit of 1 and an upper limit of 9 in a loop until it generates one of the above numbers. I was wondering if there was a simple formula like (this is the standard...
4
12536
by: manontheedge | last post by:
I've got an issue with the random number generator I'm using in C++. It's randomness is fine, but the problem is that I'm automating something that runs a few thousand times in a couple of seconds, and it's going so fast that the random numbers don't change. If I'm manually running the code and taking a second or two in between calls to the function with the random number generator in it, it's fine. It's when it's getting called quickly...
0
8182
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8627
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8579
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8279
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6088
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4052
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1425
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.