473,394 Members | 1,935 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,394 software developers and data experts.

How can I apply the same identifier (8 digit random number) to each set of ten rows?

Hi,

I have a query that pulls information I need and lists out certain "REP ID"s. I need some sort of update script the will take the first ten and assign them all the same 8 digit number in another column called "Sheet Barcode". It may not always end in exactly ten rows, but I would need a new number assigned for the following six, for example, as long as its still the same REP ID. Please see below for an example of what I am looking for.

Auto REP ID Sheet Barcode
1 22687 12345678
2 22687 12345678
3 22687 12345678
4 22687 12345678
5 22687 12345678
6 22687 12345678
7 22687 12345678
8 22687 12345678
9 22687 12345678
10 22687 12345678
11 22687 23456789
12 22687 23456789
13 22687 23456789
14 22687 23456789
15 22687 23456789
16 22687 23456789
17 22687 23456789
18 22687 23456789
19 22687 23456789
20 22687 23456789
21 22687 34567891
22 22687 34567891
23 22687 34567891
24 22687 34567891
25 33204 45678912
26 33204 45678912
27 33204 45678912
28 33204 45678912
29 33204 45678912
30 33204 45678912
31 33204 45678912
32 33204 45678912
33 33204 45678912
34 33204 45678912


The randomly generated number can be anything just as long as it's a number and is not duplicated. Thanks in advance for any insight!!
Mar 22 '11 #1
14 2826
ADezii
8,834 Expert 8TB
I just wish to clarify a few points before proceeding:
  1. Generate a Unique, 8-Digit, Random Number for each Series of 10 [REP ID]s.
  2. If the [REP ID] is the same, a new Random must be generated for each Interval of 10 Records, specifically at: Records 11, 21, 31, etc.
  3. Anytime the [REP ID] changes, so does the 8-Digit Random Number.
  4. Does the Randomly Generated Number need to be formatted to 8 Digits if it is less than 8 Digits in length, namely: 00009823, 00239634, 00000203, 09987600, etc.?
  5. Are the above statements correct?
Mar 22 '11 #2
Rabbit
12,516 Expert Mod 8TB
Rnd(([RepCode] & (([AutoID] - 1) \ 10)) * -1) AS PseudoRandomNumber

Edit: Nevermind, guess that doesn't work. I thought it's supposed to give the same number if the seed doesn't change.

Edit 2: Nevermind again, I was right the first time. It just has to be a negative number.
Mar 22 '11 #3
NeoPa
32,556 Expert Mod 16PB
Unfortunately Rnd() can return the same number even if the seed is different.

I would actually suggest using code to process through the records. Every time a new value is determined a check should be done on the existing data in the table to ensure the value has not already been used. If it has, simply drop it and go for another one. Rnd() with no seed parameter should provide the next random number in sequence from the previously passed seed.
Mar 23 '11 #4
ADezii
8,834 Expert 8TB
@NeoPa - Isn't it a little more complicated than just generating another Random every time the [REP ID] changes? A new Random is also needed for every new series of 10 Records for any given [REP ID], and for any remaining Records after a series of the last 10 (Post #1). It could also be that I am over complicating matter again! (LOL).
Mar 23 '11 #5
NeoPa
32,556 Expert Mod 16PB
ADezii:
It could also be that I am over complicating matter again! (LOL).
No my friend. You simply missed a clever trick of Rabbit's.

If you look carefully at the seeding within the Rnd() call you'll see that it changes after every ten records (related to [Auto ID]).

If it's a post from Rabbit, you can expect something pretty clever and fiddly in there somewhere ;-)
Mar 23 '11 #6
ADezii
8,834 Expert 8TB
Thanks NeoPa, he is, after all, a rascally Rabbit! (LOL).
Mar 23 '11 #7
Rabbit
12,516 Expert Mod 8TB
My bad, I missed the part at the end of the post about it being unique. A function would be the only way to guarantee uniqueness. Although I do wonder about the purpose of all this and whether a random number is truly needed.
Mar 23 '11 #8
ADezii
8,834 Expert 8TB
I'm probably off on a Tangent again, but I was thinking along the lines of a very simple Function to generate a Random Number between 1 and 99,999,999 as a Formatted String. The odds of any Duplication would be a rarity, to say the least.
Expand|Select|Wrap|Line Numbers
  1. Public Function fGen8DigitRndNum()
  2. Randomize
  3.  
  4. fGen8DigitRndNum = Format$(Int(Rnd * 99999999) + 1, "00000000")
  5. End Function
Mar 23 '11 #9
NeoPa
32,556 Expert Mod 16PB
John, There's enough info here to do the full job properly. Let us know where you are with that, how you get on or if you need more help on the matter.

Wascally Wabbit:
Although I do wonder about the purpose of all this and whether a random number is truly needed.
I read the request for a random number as indicating that it simply has no specific requirements. Nothing in the question says it needs to be unpredictable in any way. Simply that it's different from any of the other values used. As such, there is no requirement to use Rnd(), though it seems to fit the bill quite nicely ;-)
Mar 23 '11 #10
Rabbit
12,516 Expert Mod 8TB
Well, it's just that if randomness is not truly needed. You can achieve the same results by using RepCode & ((AutoID - 1) \ 10)

ADezii, you would still need to keep track of the RepID and if 10 records have already been issued that random number. Plus Rnd by itself will move on to the next random number.
Mar 23 '11 #11
NeoPa
32,556 Expert Mod 16PB
I'm sure what you had before, or a minor variation of it, is fine for producing the requisite value. It's now just a question of ensuring it's used up to ten times etc.

Expand|Select|Wrap|Line Numbers
  1. Int(Rnd('-' & [RepCode] & (([AutoID] - 1) \ 10)) * 100000000)
This produces a value between 0 and 99,999,999.
Mar 23 '11 #12
Thanks, everyone! I did not expect so much help in that short amount of time. I will try the Rnd() function tomorrow and let you know how it comes out. You are correct, true randomness is not necessary I just need a unique identifier for each set of ten records per Rep ID that also changes for each change in Rep ID itself. This logic seems like it would work. I will keep you posted and thanks again!!
Mar 23 '11 #13
This worked great! Although strangely it produces seven digit numbers sometimes, instead of eight. It's not a big deal though and I can definately make it work. For reference this is what I put into the access query:

Expr1: Int(Rnd('-' & [REP ID] & (([AutoNumber]-1)\10))*100000000)

THANKS AGAIN!!
Mar 24 '11 #14
NeoPa
32,556 Expert Mod 16PB
See post #9 for what to do to ensure the number strings are 8 digits (Format()). This doesn't ensure that the lowest number is 10,000,000 mind you. That was never part of the request. Possible of course, but we try to answer the question as submitted.
Mar 24 '11 #15

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

Similar topics

16
by: Jason | last post by:
Hi, I need a way to use random numbers in c++. In my c++ project, when using the mingw compiler I used a mersenne twister that is publicly available and this did its job well. Now I have...
14
by: Debbie Lucier | last post by:
How would I generate a even random number each time? I can generate a random number each time but not an even one? Here is the code I use for the random number from 1-100. <script...
4
by: Greg Strong | last post by:
Hello All, Is it possible to create multiple random numbers in a query where there are numerous records? I've created a custom function. When I use it in a query it creates the same random...
2
by: Ronny Mandal | last post by:
Is there a function that will do this task properly? -- Thanks Ronny Mandal
16
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...
2
by: Henry | last post by:
Hi, How can I generate an eight digit random? Can I use the staff name to generate it? May I ask is there any sample c# code to see? Thanks
6
by: kilter | last post by:
Anyone know of a routine that will return the number of rows and columns in a matrix?
13
by: rhitx | last post by:
Hello: I'm trying create a random number generator, which will generate either number 1, 2, 3. I tried to do it like: int random_number() { int no_goal, rand_Number;
1
by: scripter407 | last post by:
I know there are some methods like montecarlo method to test for primality but find it difficult to implement these algorithm. I would like you give your suggestions on it. Hope you all find this...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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...

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.