473,503 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating random unique numbers and insert them into a columun.

1 New Member
Hey people,


I wanted to generate a random number (for a unique and unpredictable memberID) and insert it into every memberID column which has not a memberID already (equals NULL).
I dont want to change the already generated memberIDs in the meantime.

Expand|Select|Wrap|Line Numbers
  1. SELECT FLOOR(10000 + RAND() * 89999) AS random_number
  2. FROM customer
  3. WHERE "random_number" NOT IN (SELECT memberID FROM customer)
  4. LIMIT 1
This is the SQL query to generate a unique random number (I hope :D).
So how can I manage the rest now?

Or even better, can I generate a random, unique and unpredictable ID automatically for every new member I create?
Jul 5 '17 #1
1 5132
Luuk
1,047 Recognized Expert Top Contributor
Maybe it's easier ti use the MySQL function UUID_SHORT() for this?

Another solution might be to create a trigger
Oct 28 '17 #2

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

Similar topics

5
2884
by: Ross MacGregor | last post by:
I have a very simple yet complicated problem. I want to generate a random list of indices (int's) for a container. Let's say I have a container with 10 items and I want a list of 3 random...
4
10723
by: August1 | last post by:
A handful of articles have been posted requesting information on how to use these functions in addition to the time() function as the seed to generate unique groups (sets) of numbers - each group...
1
30884
by: Intaek LIM | last post by:
generally, we use srand(time(0)) to generate random numbers. i know why we use time(0), but i can not explain how it operates. first, see example source below. ...
3
6315
by: Bob Alston | last post by:
I have a routine to copy data to new versions of my app via insert into sql statements. Unfortunately, due to evolution of my app, sometimes the new version has more restrictive editing than an...
1
1920
by: Wally | last post by:
I am after VB.net code for a random number generator that will generate 10 different numbers between 1 and 10 and put them into an array. For example I want the output to be something like...
1
2651
by: Velhari | last post by:
Hi, I am a beginner. Please tell me, For generating Random Numbers, Initially why we are going for seed method. And another question is that, I want to print unique random number how to print by...
1
1689
by: ronnchpra | last post by:
Hello, Im still kind a new to C++ Programming? Can anyone help me write a small code that would generate 50 random numbers, say from between 1-100? This is a small part of a program I'm...
11
2995
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...
15
4874
by: rajeevs | last post by:
I have an access table with records having unique numbers in one field. I would like to duplicate the record except the unique number and while duplicating I like to give a different number. I have...
2
1629
by: mgdvicky | last post by:
I need to generate unique random number to show into the text box value and also perform insert,delete,update operation using java script. I need your solution which is better way using mysql or...
0
7207
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
7093
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
7291
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
7468
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...
1
5023
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...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
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 ...
0
402
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...

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.