79468147

Date: 2025-02-25 23:48:15
Score: 0.5
Natty:
Report link

I just randomly came across this 10 year old thing. It's not helpful.

Don't waste yer brain-bits deciding things.

Never think about ports or random process/service uids again. Just use this thinger. I been doin' as much for longer than this question's been on the stack.

Plug the name of your process in to this wee thing. Deterministically random - same input, same output. Never think. Thinking hurts.

#!/usr/bin/bash

# pick a port or uid
# ports and uids are both 16 bit but ports 49151:65535 are considered ephmeral/dynamic per rfc_6335
# some linux distros, including debian ffs, use 32768:60999
# i *think* systemd fusses with uids above 50000, so we'll just go with a nice, safe 12-15 bit range.
# cut the first 16 bits out of an md5, and mod it.
min=4096
max=32767
hash=$(printf '%s' "$1" | md5sum | cut -d" " -f1)
bytes=$((0x${hash:0:4}))
mod=$((bytes % max +min))
printf '%s\n' $mod

(ya, cuttin' the bits out is redundant - I do other crap, too, y'know)

(and ya, I knows that UIDs are 32-bit now. I'm old and stuck in the past. do ya have a good reason for fussing with IDs higher than the 16 bit range? maybe, but I don't see the that comin' up on Stack anytime soon)

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: kelly