How do I make a top-down terrain generation system with chunks?

Hi there,

I’m trying to create a vampire survivor and I would like to implement a terrain generation system using chunks. Specifically, I want to divide my game world into small sections and generate terrain as the player explores each chunk.

Here’s what I’m looking to achieve:
Each chunk should be generated when the player comes close to its borders and unloaded when the player moves away from it. This will ensure that the game only generates terrain that the player needs to see and I could add some randomzing stuff on top of that.