Serial Number

techElder

Well-known member
I was a little surprised not to find any hits by using Google here to find "serial number".

Anyway, my need was to create a way to get a sensor transceiver to create its own serial number that is relatively unique. In other words it would be easier to reprogram one or two units with duplicate numbers rather than create unique serial numbers for every unit as it is programmed (not to mention keeping track as I do that.)

There will certainly be less than 100 sensors, and there are no real security issues involved.

So, I came up with the following code, but since I am moving, I don't have a way to put it on hardware at the moment. Was wondering what you thought about it.

PS. I do understand all the ramifications around generating RANDOM numbers etc. ad nauseum. :D

Code:
[color=Blue]symbol [/color][color=Black]serialNumber [/color][color=DarkCyan]= [/color][color=Purple]w13[/color]

[color=Blue]data [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]([/color][color=Navy]0[/color][color=Black], [/color][color=Navy]0[/color][color=Blue]) [/color][color=Green]' preload zero[/color]

[color=Blue]read [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]WORD [/color][color=Black]serialNumber[/color]
[color=Blue]if [/color][color=Black]serialNumber [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then [/color][color=Green]' create a serial number
   [/color][color=Blue]readinternaltemp IT_RAW_L[/color][color=Black], [/color][color=Navy]0[/color][color=Black], [/color][color=Purple]w0
   [/color][color=Blue]random [/color][color=Purple]w0
   [/color][color=Green]'pause w0 ' random delay
   [/color][color=Black]serialNumber [/color][color=DarkCyan]= [/color][color=Purple]w0
   [/color][color=Blue]random [/color][color=Black]serialNumber
   [/color][color=Blue]write [/color][color=Navy]0[/color][color=Black], [/color][color=Blue]WORD [/color][color=Black]serialNumber[/color]
[color=Blue]endif[/color]
 

AllyCat

Senior Member
Hi,

It depends if you're using PE5 or PE6, the value of your supply rail and if it is regulated. :p

For RAW_L, PE5 actually returns the High value, so with a moderately consistent supply voltage and PICs from the same tube, there might not be much variation at all. (The correct) RAW_L only has a tempco of around 1 lsb per degree C. Added to that, RANDOM will always generate exactly the same value from the same seed, so you may have a lot of reprogramming to do.

PE6 has fixed the RAW_L bug, but uses a surprisingly large number of bytes, so probably something better can be devised. IMHO you'd probably do much better to read the 16-bit value from one (or more) of the TOUCH16 sensor pins.

Cheers, Alan.

EDIT: I realise I've mis-remembered the meaning of the _L and _H. It's the number of diodes used, not the High or Low byte of the result (which I now normally access via PEEKSFRs). But I still think that readinternaltemp is a rather poor randomising mechanism for PICs from the same tube at the same time.
 
Last edited:

techElder

Well-known member
Thanks, AllyCat. Good info.

Bear, if the UK had a town like Hondo, Texas or Cuero, Texas I just might consider it, but as long as you folks get your enchiladas out of a can, I'm going to stay near a lady here that makes some really good ones to eat when your belly is touching your backbone.
 

Buzby

Senior Member
If your sensors include DS18B20 devices ( or just about any other 1-Wire device ) then you have a unique serial number built in.

Also, there is the DS2401, which is just a serial number and nothing else.

On Google Maps, Hondo looks like something out of Minecraft :)

Cheers,

Buzby
 

techElder

Well-known member
1-Wire sensors are not in the picture. The serial number only needs to be two bytes.

Perhaps I'll just put 100 RANDOMIZED serial numbers in EEPROM and choose one at RANDOM.

EDIT: I forgot to say that I'm targeting an 08M2 and all the pins are used.

EDIT2: Also, on further thought, if I use a list of numbers they wouldn't have to be randomized at all.

PS. Hondo Texas is well known for its historical sign that says, "This is God's country. Don't drive through it like hell!"
 
Last edited:

darb1972

Senior Member
Ok, just spit balling here. Can you use the Time variable as the seed to generate a random serial number? Only need to generate it once and store in the internal EEPROM. Should be random enough not to be duplicated from one device to the next. Could be formulated to fall within a certain range.
 

Buzby

Senior Member
Hi texas,

Your slave address problem seemed familiar, I thought maybe we had discussed it before.

I was right, it was about 18 months ago : www.picaxeforum.co.uk/showthread.php?27676

Did none of these ideas float your boat ?.

Cheers,

Buzby

EDIT : I've just thought of how to simplify Option 4 so that it doesn't need Bluetooth, or programming the phone.
 
Last edited:

techElder

Well-known member
Your slave address problem seemed familiar, I thought maybe we had discussed it before.
Buzby, right you are (and good memory) but on that project I ended up using a pushbutton and a separate slot for manually programming an ID. Worked very well after all the suggestions from the group.

This one is using an 08 with no pins left and a minimal hardware spec to work with.

Can you use the Time variable as the seed to generate a random serial number?
darb1972, Time only changes once every 1/2 second @ 32 MHz. Takes awhile to get a number.
 

techElder

Well-known member
Hippy, I mangled your code here and came up with the following, but it seems like, in the short term, the seconds and minutes kind of offset and tend to create the same numbers.

Code:
[color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]
[color=Purple]w2 [/color][color=DarkCyan]= [/color][color=Navy]0[/color]

[color=Blue]do
   lookup [/color][color=Purple]b0[/color][color=Black], [/color][color=Blue](ppp_datetime[/color][color=Black],[/color][color=Navy]0[/color][color=Blue])[/color][color=Black],[/color][color=Purple]b1
   [/color][color=Blue]if [/color][color=Purple]b1 [/color][color=DarkCyan]<> [/color][color=Navy]0 [/color][color=Blue]then                           [/color][color=Green]' exit not ascii
      [/color][color=Blue]if [/color][color=Purple]b1 [/color][color=DarkCyan]> [/color][color=Navy]47 [/color][color=DarkCyan]and [/color][color=Purple]b1 [/color][color=DarkCyan]< [/color][color=Navy]58 [/color][color=Blue]then            [/color][color=Green]' ascii numbers only removes constants
         [/color][color=Blue]sertxd([/color][color=Black]#[/color][color=Purple]b1[/color][color=Black],[/color][color=Red]" "[/color][color=Blue])                     [/color][color=Green]' ascii numbers summed
         [/color][color=Purple]w2 [/color][color=DarkCyan]= [/color][color=Purple]w2 [/color][color=DarkCyan]+ [/color][color=Purple]b1                        [/color][color=Green]' sum ascii numbers
         'b2 = $FF - w2 : b2 = b2 + 1 ' one's complement; two's complement
      [/color][color=Blue]endif
      inc [/color][color=Purple]b0                                 [/color][color=Green]' next character
   [/color][color=Blue]endif
loop until [/color][color=Purple]b1 [/color][color=DarkCyan]= [/color][color=Navy]0                            [/color][color=Green]' finished with string[/color]

[color=Blue]sertxd(ppp_datetime[/color][color=Black],[/color][color=Red]" Sum: "[/color][color=Black],#[/color][color=Purple]w2[/color][color=Black],[/color][color=Red]" Done"[/color][color=Black],[/color][color=Blue]cr[/color][color=Black],[/color][color=Blue]lf)[/color]
 

Buzby

Senior Member
I saw hippy's post, and assumed he meant just concatenate the digits of HH:MM:SS to make the serial number, not add them together.

Adding will always create duplicates.
 

hippy

Technical Support
Staff member
I'd be tempted to shift left and add the raw ASCII, colons and all. Maybe times 10 and add would be more unique. Using a CRC addition is probably the best. I hadn't thought through what would be best, but the bigger the number arrived at the better; 0-65535 is better than 0-10.

Perhaps use one part to create a value, and another to create a count of how many times to randomise that.

There are probably an infinite number of ways to do it and it probably requires someone with more solid expertise in randomness theory than I have. Or some experimenting.
 

AllyCat

Senior Member
Hi,

Using the PPP_* pre-processor symbols it is possible to program the time of download into the PICAXE and then use that...
IMHO, as usual, hippy comes up with the most practical solution, but then concatenate (join is series) the 3 LS bits of the H:MM:SS ASCII digits (and the LSb from the 10s of Hours) to give your 16-bit Serial Number.

But if you want a fully autonomous method and are prepared to look a little into the base PIC data sheet (section 27 for most M2s) then the touch sensor could be good enough. If no pin can be arranged to have a "high impedance" (even at boot up) then maybe try selecting an "invalid" multiplexer input and/or NOT enabling the ANSEL input.

TOUCH basically uses a 16-bit counter, running at a relatively "unstable" frequency (also the "noise detection" frequency mode looks interesting). The touch oscillator can run during sleep, so at the program start you could enable the oscillator, SLEEP for a few seconds, which uses the Watchdog timer that is also not very precise (but not as bad as the PICaxe manual implies) and then after waking, read the 16-bit count.

Cheers, Alan.
 

hippy

Technical Support
Staff member
This seemed to work somewhat, not exhaustively tested, just kept clicking RUN in simulation ...

Code:
w1 = 0
Do
  LookUp b0, ( ppp_time, 0 ), b1
  If b1 <> 0 Then
    w1 = b1 * 17 + w1 * 3 + b1
    b0 = b0 + 1
  End If
Loop Until b1 = 0
SerTxd( #w1, CR, LF )
 

techElder

Well-known member
Hippy's changes do produce a duplicate or two, but only if I can program an 08M2 within close seconds of time. Typical timing seems to produce that wide range of numbers that Hippy spoke of. Thanks!

IMHO, as usual, hippy comes up with the most practical solution, but then concatenate (join is series) the 3 LS bits of the H:MM:SS ASCII digits (and the LSb from the 10s of Hours) to give your 16-bit Serial Number.
AllyCat, I'm going to try your suggestion, too.

The challenge is that the preprocessor stuff only changes once during a simulation, so it isn't quick to simulate a lot of numbers in a row. That's the good thing about it, too. :D
 

hippy

Technical Support
Staff member
This should produce fairly unique codes unless programmed within a second of each other. It's basically a CRC16 calculation -

Code:
Symbol POLYNOMIAL = $A001 

Symbol dataByte   = b0 ;         Must be b0
Symbol index      = b1
Symbol crc        = w1 ; b3:b2 - Must be w2
Symbol k          = w2 ; b6:b4

crc = 0
For index = 0 to 7
  LookUp index, ( ppp_time ), dataByte
  k = bit0 ^ bit16 * POLYNOMIAL : crc = crc / 2 ^ k
  k = bit1 ^ bit16 * POLYNOMIAL : crc = crc / 2 ^ k
  k = bit2 ^ bit16 * POLYNOMIAL : crc = crc / 2 ^ k
  k = bit3 ^ bit16 * POLYNOMIAL : crc = crc / 2 ^ k
Next
SerTxd( #crc, CR, LF )
 

hippy

Technical Support
Staff member
I saw hippy's post, and assumed he meant just concatenate the digits of HH:MM:SS to make the serial number, not add them together.
Actually that does seem the best option. The value doesn't have to be random nor vastly different, just unique. Unless two devices are programmed at exactly the same time of day there won't be a duplicate.

This allows times 00:00:00 to 18:12:15 to give as a unique code, 0 to 65535 -

Code:
; #Define t ppp_time
  #Define t "18:12:15"

Lookup 0, (t), b0 : w1 =           b0 - "0"
Lookup 1, (t), b0 : w1 = w1 * 10 + b0 - "0"
Lookup 3, (t), b0 : w1 = w1 *  6 + b0 - "0"
Lookup 4, (t), b0 : w1 = w1 * 10 + b0 - "0"
Lookup 6, (t), b0 : w1 = w1 *  6 + b0 - "0"
Lookup 7, (t), b0 : w1 = w1 * 10 + b0 - "0"

SerTxd( #w1, CR, LF )

b17 = w1 // 10 : w1 = w1 / 10
b16 = w1 //  6 : w1 = w1 /  6
b14 = w1 // 10 : w1 = w1 / 10
b13 = w1 //  6 : w1 = w1 /  6
b11 = w1 // 10 : w1 = w1 / 10
b10 = w1

SerTxd( #b10,#b11,":",#b13,#b14,":",#b16,#b17, CR, LF )
One can tweak that to move time forward; for example 01:00:00 to 19:12:15, and 04:00:00 to 22:12:15 would cover most working days. 22 = 18 + 4, hence the +4 and -4 adjustment ...

Code:
; #Define t ppp_time
; #Define t "18:12:15"
  #Define t "22:12:15"

Lookup 0, (t), b0 : w1 =           b0 - "0"
Lookup 1, (t), b0 : w1 = w1 * 10 + b0 - "0" - 4
Lookup 3, (t), b0 : w1 = w1 *  6 + b0 - "0"
Lookup 4, (t), b0 : w1 = w1 * 10 + b0 - "0"
Lookup 6, (t), b0 : w1 = w1 *  6 + b0 - "0"
Lookup 7, (t), b0 : w1 = w1 * 10 + b0 - "0"

SerTxd( #w1, CR, LF )

b17 = w1 // 10 : w1 = w1 / 10
b16 = w1 //  6 : w1 = w1 /  6
b14 = w1 // 10 : w1 = w1 / 10
b13 = w1 //  6 : w1 = w1 /  6 + 4
b11 = w1 // 10 : w1 = w1 / 10
b10 = w1

SerTxd( #b10,#b11,":",#b13,#b14,":",#b16,#b17, CR, LF )
It still works outside of 04:00:00 to 22:12:15 but there's more a chance of a clash when that is done.
 

techElder

Well-known member
That works great, Hippy.

However, I noticed that PE6.0.8.6 Code Explorer tab doesn't show bit values for w2(b4:b5).

Is there a switch to make them show up? They don't show for 20X2, either.

EDIT: crossed path with your last post. Will look at that, too.
 
Last edited:

hippy

Technical Support
Staff member
I noticed that PE6.0.8.6 Code Explorer tab doesn't show bit values for w2(b4:b5).
There are only 32 bit variables, w0 and w1, b0 through b3.

Raw binary values aren't shown for any word variables, but the 8-bit binary values are shown for the component byte variables.

I believe the rationale for this was that having 16-digit raw values clutters the panel display and anyone needing to know the bit values for words could easily work it out from the hex display or the byte binary values.
 

techElder

Well-known member
Hippy, I was confused in post #18 where you used "bit16" and the code passed syntax check and ran fine. Just didn't see it in PE Code Explorer.
 

techElder

Well-known member
Code Snippet suggestion

Here's what I would post as a code snippet unless someone can suggest some changes.

I suppose it could be mashed all into a MACRO. I'll probably do that in my code.

Code:
[color=Green]' EXAMPLE[/color]

[color=Blue]symbol [/color][color=Black]serialNumber [/color][color=DarkCyan]= [/color][color=Purple]w1[/color]
[color=Blue]symbol [/color][color=Black]serialNumberAddress [/color][color=DarkCyan]= [/color][color=Navy]0               [/color][color=Green]' location in EEPROM where serialNumber is stored

'  #Define pppTime ppp_time
'  #Define pppTime "18:12:15"
'  #Define pppTime "22:12:15"

'---------------------------------
[PLAIN]'------[ READ SERIALNUMBER ]------[/PLAIN]
'---------------------------------[/color]

[color=Blue]read [/color][color=Black]serialNumberAddress, [/color][color=Blue]WORD [/color][color=Black]serialNumber[/color]
[color=Blue]if [/color][color=Black]serialNumber [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
   gosub [/color][color=Black]UID [/color][color=Green]' uses b0 and w1
   [/color][color=Blue]write [/color][color=Black]serialNumberAddress, [/color][color=Blue]WORD [/color][color=Black]serialNumber[/color]
[color=Blue]endif

end[/color]

[color=Black]UID:
   [/color][color=Green]'  Create a unique ID number (serial number) for small network sensor ID.
   '  Using the PPP_* pre-processor symbols it is possible to program the time of download into the PICAXE 
   '     and then use that to create the ID. Presumably one would check a value in EEPROM to see if it is
   '     zero or has one of these IDs saved at that location as the sensor serial number.
   '  Based on posts started on the PICAXE FORUM at:
   '     [url]http://www.picaxeforum.co.uk/showthread.php?29537-Serial-Number[/url]
   '  Final code is from Hippy's post #19 part B.

   '  The unique number is returned in w1.
   '  #Define pppTime ppp_time
   '  Uses b0, w1
   '  The value returned in w1 isn't random nor vastly different, just unique.
   '  Unless two devices are programmed at exactly the same time of day there won't be a duplicate.
   '  This allows times 00:00:00 to 18:12:15 to give as a unique code, 0 to 65535 however
   '     adding the "- 4" allows times from 04:00:00 to 22:12:15.
   '     It still works outside of 04:00:00 to 22:12:15 but there's more chance of a clash.
   '
   [/color][color=Blue]Lookup [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]=           [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
   [/color][color=Blue]Lookup [/color][color=Navy]1[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]* [/color][color=Navy]10 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0" [/color][color=DarkCyan]- [/color][color=Navy]4
   [/color][color=Blue]Lookup [/color][color=Navy]3[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]*  [/color][color=Navy]6 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
   [/color][color=Blue]Lookup [/color][color=Navy]4[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]* [/color][color=Navy]10 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
   [/color][color=Blue]Lookup [/color][color=Navy]6[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]*  [/color][color=Navy]6 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
   [/color][color=Blue]Lookup [/color][color=Navy]7[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]* [/color][color=Navy]10 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"

   [/color][color=Blue]return[/color]
 
Last edited:

techElder

Well-known member
Code Snippet suggestion

So, I went ahead and converted it to a macro:

Code:
[color=Navy]#Macro [/color][color=Black]UID[/color][color=Blue]([/color][color=Purple]serialNumber[/color][color=Black],[/color][color=Blue]SERIALNUMBERADDR)
   [/color][color=Green]'  Create a unique ID number (serial number) for small network sensor ID.
   '  Using the PPP_* pre-processor symbols it is possible to program the time of download into the PICAXE 
   '     and then use that to create the ID. Presumably one would check a value in EEPROM to see if it is
   '     zero or has one of these IDs saved at that location as the sensor serial number.
   '  Based on posts started on the PICAXE FORUM at:
   '     http://www.picaxeforum.co.uk/showthread.php?29537-Serial-Number
   '  Final code is from Hippy's post #19 part B.

   '  The unique number is returned in w1.
   '  #Define pppTime ppp_time
   '  Uses b0, w1
   '  The value returned in w1 isn't random nor vastly different, just unique.
   '  Unless two devices are programmed at exactly the same time of day there won't be a duplicate.
   '  This allows times 00:00:00 to 18:12:15 to give as a unique code, 0 to 65535 however
   '     adding the "- 4" allows times from 04:00:00 to 22:12:15.
   '     It still works outside of 04:00:00 to 22:12:15 but there's more chance of a clash.
   [/color][color=Blue]read SERIALNUMBERADDR[/color][color=Black], [/color][color=Blue]WORD [/color][color=Purple]serialNumber
   [/color][color=Blue]if [/color][color=Purple]serialNumber [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]then
      Lookup [/color][color=Navy]0[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]=           [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
      [/color][color=Blue]Lookup [/color][color=Navy]1[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]* [/color][color=Navy]10 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0" [/color][color=DarkCyan]- [/color][color=Navy]4
      [/color][color=Blue]Lookup [/color][color=Navy]3[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]*  [/color][color=Navy]6 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
      [/color][color=Blue]Lookup [/color][color=Navy]4[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]* [/color][color=Navy]10 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
      [/color][color=Blue]Lookup [/color][color=Navy]6[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]*  [/color][color=Navy]6 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
      [/color][color=Blue]Lookup [/color][color=Navy]7[/color][color=Black], [/color][color=Blue](ppp_time)[/color][color=Black], [/color][color=Purple]b0 [/color][color=Black]: [/color][color=Purple]w1 [/color][color=DarkCyan]= [/color][color=Purple]w1 [/color][color=DarkCyan]* [/color][color=Navy]10 [/color][color=DarkCyan]+ [/color][color=Purple]b0 [/color][color=DarkCyan]- [/color][color=Red]"0"
      [/color][color=Blue]write SERIALNUMBERADDR[/color][color=Black], [/color][color=Blue]WORD [/color][color=Purple]serialNumber
   [/color][color=Blue]endif[/color]
[color=Navy]#endm[/color]
 
Last edited:

techElder

Well-known member
As it stands, this routine works very well for me. Thanks, Hippy!

Also, thanks go to Buzby for swerving this thread in the final direction.

BESQUEUT, are you suggesting that there should be a value check of #ppp_time to see if it is more than one second greater than the last one?
 

techElder

Well-known member
Another enhancement would be to be able to select a range of numbers to create.

For instance, in my other project, I limited the ID number so only ASCII BCD 1 - 99 would be transmitted, thus avoiding ASCII control characters, CR and LF. I was receiving packets in terminal programs where those "funny" characters would cause actions to be performed.
 

hippy

Technical Support
Staff member
Another enhancement would be to be able to select a range of numbers to create.
The problem there is that once you start restricting things there is a greater chance of a duplicate. Using an 8-bit time of download hash would mean there's only a 4 minute period in which all would be unique.

I don't know what the detailed maths would be for 100 items being allocated one of 256 numbers, but if 50 had unique numbers, there's a 50 in 256 chance of a clash for the next, almost 20%, rising to almost 40% for the last.
 

AllyCat

Senior Member
Hi,

I don't know what the detailed maths would be for 100 items being allocated one of 256 numbers,
There's almost an absolute certainty of at least one clash. It's the old Birthday Paradox.

It needs only 23 people in a room for a 50% chance of two having a common birthday. That rises to 99.9% for only 75 people over the 365 days.

Cheers, Alan.
 
Top