Interaction counter. Here’s an example for creating a dog interaction counter.
In a passage titled StoryInit create a default value
<<set $dog_interactions to 0>>
In each interaction passage you can add
<<set $dog_interactions += 1>>
Or, if you want to only increase the counter the first time a player visits a passage
<<if visited() is 1>><<set $dog_interactions += 1>><<endif>>
Then on the passage where you want the player to buy the dog, after eg. five interactions, insert this code:
<<if $dog_interactions gte 5>> <<link "Buy Dog">> <<goto "You bought a dog">> <</link>> <<endif>>
The easiest way to repeat this would to be to create similar counters for other animals, and include all of the links on the same page in sequence.
Randomizer. If you want to randomize the animal that players see, there are various ways to do that. I assume you would want to animal to be randomly chosen as soon as the game begins without giving a player a choice.
Say you have three animals. In your StoryInit passage write
<<set $animal to random(0,2)>>
Then throughout your game, let’s say dog is 0, cat is 1, and fish is 2
<<if $animal eq 0>> Insert whatever dog text and code is necessary here <<endif>>
<<if $animal eq 1>> Insert whatever cat text and code is necessary here<<endif>>
<<if $animal eq 2>> Insert whatever fish text and code is necessary here <<endif>>
To combine it with the “Buy dog” link in the interaction example
<<if $animal eq 0>><<if $dog_interactions gte 5>> <<link "Buy Dog">> <<goto "You bought a dog">> <</link>> <<endif>><<endif>>