# Boards

## Generating unique numbers

I need to generate a unique number that links together two constant numbers both of which could be consecutive... I was thinking of multiplying everything by the power of 3.

Do you think this will work?

**Beacon**-*Gravity Pairs***BEAK>**-*>>>*- In The Court Of The Crimson Imp: DiS Meets
**Gazelle Twin** **Some Velvet Mixtape**: 2018 In Reverb, Delay, Distortion & Drone #2- We Love EU: The Past and Future of Polish Mythology
- 30 Years Of
**Therapy?**: Still Criminally Underrated - A Celebration Of Sound: DiS Does
**Le Guess Who? 2018** **Interpol**@ Royal Albert Hall

I need to generate a unique number that links together two constant numbers both of which could be consecutive... I was thinking of multiplying everything by the power of 3.

Do you think this will work?

## Meths, I think this one is for you.

## Is he called meths

because he is good at maths?

## meths is the plural of maths, he's got all of them covered.

## only if the questions are asked by someone from south africa

## i'll take it from here.

## yeah course.

## Whoops

I meant to say...I was thinking of adding the two constants together and the multiplying them to the power of 3.

## That wouldn't work would it?

5 and 3 and 4 and 4 and 7 and 1 and 6 and 2 would all give you the same number.

You need something a bit cleverer than that. Do you need to be able to work back to the original numbers?

## No, just something to uniquely identify them

What if I cubed one of the constant numbers and then added them. There is still a chance that the same number could re-occur but cubing the constant might reduce this likelihood..

## Especially as they are pretty big numbers

for example if I cubed the date (which is one of the constant numbers)

## It really depends on the other number but you're probably right.

I wouldn't like to bet on it, though.

Maybe you need a UUID? http://en.wikipedia.org/wiki/Universally_Unique_Identifier

## You can't do what you're asking.

Not to the nth degree, unless the numbers you're using are in a defined rigid range at some stage you risk having the same number appearing, I would think

## Yeah there is a risk I guess

But how can I minimise the risk of this happening? Would a more complicated formula work? How about multiplying by a randomly generated number?

## I can't really help you unless I know what it is you're trying to do.

This is all very vague. You need to take one number and a date and make a unique number. Can you not just put a dash between them?

## ...

I have events that occured on the same dates and different dates for the same patients and different patients. Patient number and eventdate are the two contants (largish numbers). I want an (a?) unique number for all the events that happen on the same day for the same patient.

## Oh right.

Fake it:

What's the largest patient number? Add that many digits to the end of the date (not sure what your date is - Julian Date?). Then it will be unique. Like.

If the date is 123,456,789 and patient numbers are betweeen 1 and 99,999

Then you combine them like this: Patient 1 on that date is

12,345,678,900,001

Patient 253 is

12,345,678,900,253

and patient 99,999 is

12,345,678,999,999

Each number is unique and you can always get the original numbers by dividing by 100000 and getting the integer value or getting the remainder and multiplying by 100000.

## You're Julian Date

## This is exactly what I was going to suggest

I do this sort of thing all the time when I need unique identifiers involving dates

## (thanks for trying to help)

## Yes something like this could work

If I could append one number onto the end of another.. Hmm do you know how to do this STATA?

## Hah hah. I took so long to write my reply I didn't see yours or something.

Yeah just add them together as above. I thought you needed some secret secure way of storing them, sorry! :-)

## Cheers Theo

I think I'll be able do it. Awesome.

## Though if all you're doing is trying to count occurances of patient X on date Y

then surely:

SELECT occurrence, patient_id, count(*) ORDER BY occurrence, patient_id

would give you the same thing?

## I'm not sure

I think your earlier reply will solve my problem. I have to look at other tagged events that might occur +1, +2 and +3 days after a certain type of event, but I will be a able to do this now. Thanks again :D

## Actually I forgot on that SELECT to add in a GROUP BY occurrence, patient_id

Anyway, yeah that sounds complex!

## I probably haven't explained this very well

:(

## You should probably wath Numberjacks

it's on BBC2 on weekday mornings.

Estimate 7.

## wath, watch, whatever

## 6

## you do the math

## s

## It's 'maths', Jeremy.

## 174