@@ -14,8 +14,33 @@ make_symlink_to_latest_experiment_dir() {
14
14
ln -s " ${EXP_DIR} " " ${LINK_NAME} " > /dev/null 2>&1
15
15
}
16
16
17
+ # Below is an explanation of what constitutes a 'run_id'.
18
+ #
19
+ # 0: A static digit '1'
20
+ # 1-5: A random number, left-padded with '0', then reversed
21
+ # 6-16: The current number of seconds since epoch, truncated to 10 digits, then reversed
22
+ # 17-18: The experiment number
23
+ #
24
+ # When converted to hex, this creates a pseudorandom 15 digit value. The static
25
+ # '1' and number of seconds since epoch are truncated to ensure the value
26
+ # remains at 15 digits.
27
+ #
28
+ # The order of components is very intentional. With the exception of the static
29
+ # value at the beginning, the most significant digits are also the most
30
+ # variable. This gives the best illusion of "random".
31
+ #
32
+ # The 'run_id' does not need to be cryptographically secure, only random
33
+ # *enough* such that it's extremely unlikely that two identical 'run_id's will
34
+ # ever be generated. For a collision to occur, the same experiment number during
35
+ # the same second must generate the same random number. It is theoretically
36
+ # possible to have another chance for collision in the future since the number
37
+ # of seconds since epoch is truncated, but this is only possible once every ~317
38
+ # years.
17
39
generate_run_id () {
18
- printf ' %x' " $( date +%s) "
40
+ local time_component rand_component
41
+ time_component=" $( printf " %.10s" " $( date +%s | rev) " ) "
42
+ rand_component=" $( rand=$RANDOM ; printf ' %05d' " $rand " | rev) "
43
+ printf ' %x' " 1$rand_component$time_component ${EXP_NO} "
19
44
}
20
45
21
46
# Init common constants
0 commit comments