[I7] how to make a randomized safe code

I want to have the player come across a piece of paper, on which is a random 4 digit code. The player then must use that code to open a safe.

So basically, same as the example in “Safety” of section 9.2 of the inform recipe book, except that the number that needs to be spun to would be different every playthrough.

How would I go about achieving this? Thanks

[code]The safe has a number called safecode.
When play begins:
now safecode of safe is a random number from 1000 to 9999.

A mysterious note is in disused hallway. The description is “It’s hastily scrawled with the numbers [safecode of safe] and the word ‘Shhh!’”

Then somewhere you’d have something like:

If the number spun to is safecode of safe: [magic stuff happens].