Help with generating a pseudo random number per week

mod(
  toNumber(slice(replaceAll(id(), "[a-f]", ""), 0, 6))
  * mod(timestamp(dateSubtract(dateSubtract(now(), mod(toNumber(dateAdd(now(), -2, "days")), 7), "days"), hour(now()), "hours")) / 10000, 1.23456e+6),
  1.23456e+5
)

This formula generates a pseudo-random number based on the current time and the page ID. It first removes any letters from the page ID and takes the first 6 digits (represented as a number) to use as a factor. It then takes the current time and subtracts 2 days, rounds down to the nearest week, and rounds down to the nearest hour to "freeze" the value. It then multiplies this by the factor and takes the remainder when divided by 1.23456e+6, which is then further reduced to the remainder when divided by 1.23456e+5. The result is a number between 0 and 12345.

Creating a random number is always rooted in the now() current time

dynamic =                                                            now()
hourly  =                                               dateSubtract(now(),minute(now()),"minutes")
daily   =                                  dateSubtract(dateSubtract(now(),minute(now()),"minutes"),hour(now()),"hours")
monthly =                     dateSubtract(dateSubtract(dateSubtract(now(),minute(now()),"minutes"),hour(now()),"hours"),date(now()),"days")
annually=        dateSubtract(dateSubtract(dateSubtract(dateSubtract(now(),minute(now()),"minutes"),hour(now()),"hours"),date(now()),"days"),month(now()),"months")
// and you can also "add back" time to select when the number should change over
weekly  =dateAdd(dateSubtract(dateSubtract(dateSubtract(dateSubtract(now(),minute(now()),"minutes"),hour(now()),"hours"),date(now()),"days"),month(now()),"months"), toNumber(formatDate(now(), "WW")) - 1, "weeks")
minutely=                                       dateAdd(dateSubtract(now(),minute(now()),"minutes"),toNumber(formatDate(now(), "mm")) - 1, "minutes")

the idea being that now() updates constantly, and you use dateSubtract with the values of the current time (minute(now())) to “freeze” the value to only change so often.

Together with a formula to make a number out of the page ID:

toNumber(replaceAll(replaceAll(replaceAll(replaceAll(replaceAll(replaceAll(id(), "a", "1"), "b", "2"), "c", "3"), "d", "4"), "e", "5"), "f", "6"))

You can sort by a value that updates accordingly:

weeklyRank= mod(prop("_idAsNumber"), timestamp(prop("_thisWeek")))
dailyRank = mod(prop("_idAsNumber"), timestamp(prop("_thisDay")))

Entries

Rollups