Number sequence generator that follows a set of logic?

so I’m making a generative sequencer for someone and I’m watching this https://www.youtube.com/watch?v=fXIEmMDwc7E

basically the video teaches you how to find the next chord; 1st chord of the major scale can go to any chord, 2nd chord goes to 5th chord, 4th chord goes to either 1st or 5th chord, 5th chord goes back to 1st chord etc.
so I wanna make a 4-step number sequence generator; the number after 1 can be any number within 1-7, the number after 2 is always 5, 4 to either 1 or 5 etc.
and the sequence can start in any number

anyone know how to patch something like that?