Sorry if this is a repost - my connection went as I was posting the
1st time!
I want to insert a random number, in mod 10, in a field, based on
whether another field is empty or not.
I am using the following query:
UPDATE tbl_Results SET Q11_17 = (Int((100000-50+1)*Rnd()+100 000) Mod
10)*10
WHERE Q8_17<>'';
If I run this query, all fields in Q11_17 are updated with the SAME
random number if Q8_17 is not empty.
I want every field in Q11_17 that meets the criteria to have a NEW
random number, so my question is, how do I re-initialize the Rnd
function for each field?
Thanks 8 5724
Locky wrote: Sorry if this is a repost - my connection went as I was posting the 1st time!
I want to insert a random number, in mod 10, in a field, based on whether another field is empty or not.
I am using the following query:
UPDATE tbl_Results SET Q11_17 = (Int((100000-50+1)*Rnd()+100 000) Mod 10)*10 WHERE Q8_17<>'';
If I run this query, all fields in Q11_17 are updated with the SAME random number if Q8_17 is not empty.
I want every field in Q11_17 that meets the criteria to have a NEW random number, so my question is, how do I re-initialize the Rnd function for each field?
Thanks
Call a custom function, e.g.
function Random(Max, dummy)
randomize timer
random = rnd() * Max
end function
Send a field from the query as dummy parameter, this will ensure Access
calls the function for each record otherwise it will try to be eficient
and call it once for the entire query and plonk the same result into
each row.
Hi
Thanks for such a quick reply, but I am unsure as to how to implement
this in an access query.
Could you give me more info?
Sorry!! ad*******@gmail .com wrote: Hi
Thanks for such a quick reply, but I am unsure as to how to implement this in an access query. Could you give me more info? Sorry!!
Something like: update table set field = Random(50)
That'll give every record the same number, Trevor. At least it did in
Access97. I don't think I've tried it since.
Cheap trick: Create an Autonumber field set to random... <Grin>
Or use a function that returns a random number after setting the
randomize value first. c.*******@world net.att.net wrote: Or use a function that returns a random number after setting the randomize value first.
See the function 2 posts up, that's what it does, I just forgot the
second parameter on the calling line in the last post.
Trevor Best wrote: c.*******@world net.att.net wrote:
Or use a function that returns a random number after setting the randomize value first.
See the function 2 posts up, that's what it does, I just forgot the second parameter on the calling line in the last post.
Indeed, except you don't want to do the "Randomize Timer" each pass
through the function. You only want to do it _once_. c.*******@world net.att.net wrote: Trevor Best wrote:
c.*******@wor ldnet.att.net wrote:
Or use a function that returns a random number after setting the randomize value first.
See the function 2 posts up, that's what it does, I just forgot the second parameter on the calling line in the last post.
Indeed, except you don't want to do the "Randomize Timer" each pass through the function. You only want to do it _once_.
I've not tested, what is the overhead of that?
Sorry for the long delay in replying. It's been a week!
The problem with calling Randomize on each pass through the function
has to do with the way the "Random Number Generator" works. In fact,
it's not a generator at all, it's more like a lookup table. The
Randomize statement sets the initial lookup position, then each Random
call reads the value from the table and advances the "pointer" one
record forward.
Using the (optional) setting for the Randomize statement (in this case
Timer), tells the the Random Number Generator at what position to start
at. Giving it the same "time" (for simplicity's sake) re-sets the RNG
back to the same point over and over due to the speed at which queries
run at, thus the function will return the same "random" number over and
over.
Soneone in this newsgroup a while back posted one solution to this
problem which used a STATIC variable to help the function determine if
the Randomize statement had been used before or not, and if it hadn't
then it called the Randomize statement (using Timer). I remember
trying it, however the only way _I_ could get it to work was to call
the function before I ran the query, then let the query do it's thing.
I was doing the same thing using two seperate functions, so I didn't
save the code. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
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
using the high-order bits returned by rand() instead of the
low-order bits, avoiding using rand() for anything that wants
decently random numbers, not using rand() if you want more than
approx. UINT_MAX total different sequences, and so on.
So I...
|
by: Leon |
last post by:
I need a program that generate 5 non-duplicates random number between 1-10
as string values store in an array.
Do anybody know of any good books or websites that explain how to generator
random numbers using asp.net? I know about the random namespace within .net,
but
I need a reference to some code that do the similar stated function above.
Plus If you have any coding practice ideas for the above defined project
please share them.
|
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 double value in the range
could come up with equal probability). I'd also like to be able to seed this
generator (e.g., via the clock) so that the same sequence of random values
don't come up every time.
Anybody have an easy and fast...
|
by: fatimahtaher |
last post by:
Hi,
I am supposed to create a program that generates a random number and then asks the user to guess the number (1-100). The program tells the user if he guessed too high or too low. If he guessed right, it asks the user is he/she wants to play again. If the answer is yes, it generates a random number and asks the user to guess the number again. The user can exit if he enters 0. I have created the following code so far but it does not work....
| |
by: tshad |
last post by:
I have a page that I am getting a username and password as a random number
(2 letters, one number and 4 more letters)
I have 2 functions I call:
*************************************************
Function RandomString(size as integer, lowerCase as boolean) as string
Dim builder as StringBuilder = new StringBuilder()
Dim random as Random = new Random()
Dim i as integer
dim ch as char
|
by: Anil Gupte |
last post by:
I had someone write a random number generator in C# (I am more of a VB
programmer) and they came up with the following:
public string GetRand(int count)
{
string number = "";
for (int i=0; i<count; i++)
{
Random Rnd = new Random();
number = number+Convert.ToString(Rnd.Next(0,9));
|
by: sweatha |
last post by:
Hi Friends
I have designed a form with a label box named 'Label30' and text box named 'TextBox21'. Then I have generated the random number in the label box using the coding in form load event as
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
str = "user id=sa;password=;data source=AURO-RA4;initial...
|
by: alishaikhji |
last post by:
I am working on a program which will need several different integer and float random numbers at different stages, for example:
- At one point, I need a random number (float) in the range 0.1 to 10.0
- At one point, I need a random number (float) in the range 0.5 to 1.5
- At one point, I need a random number (float) in the range 0.3 to 3.0
- At one point, I need a random number (float) in the range 0.1 to 10.0
Also, I need to make it sure...
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |