Q:

Generate a random number for each day

I'm looking a way to generate a random number for a day and that this random number remains stable for the entire day. The next day, the code will generate another random number and so on.
I precise that I don't need to assign the same random number for the same day each year.
The actual code :
# Data
MyMax <- 45
MyValues <- paste0("The video of the day is : video_", seq(1:MyMax))

# Random generator
MyRandomNumber <- sample(1:MyMax, 1)

# Output
print(MyValues[MyRandomNumber])

Expected output :
-> Each time that I use the code the December 16, 2017 :
[1] "The video of the day is : video_35"
[1] "The video of the day is : video_35"

-> Each time that I use the code the December 17, 2017 :
[1] "The video of the day is : video_48"
[1] "The video of the day is : video_48"

-> Each time that I use the code the December 16, 2018 :
[1] "The video of the day is : video_12"
[1] "The video of the day is : video_12"

A:

# specify maximun random number (minimum is 1)
MyMax <- 100

# this will make sure randomisation remains stable at each day
set.seed(as.numeric(Sys.Date()))

# show the randomised value
paste0("The video of the day is : video_", sample(1:MyMax, 1))

# [1] "The video of the day is : video_79"

No matter how many times you run this code today, you'll always get the same output. Tomorrow it will change and will remain stable for the whole day, etc.

