baker-rrr is correct, in any case you cannot rely on the problem not reoccurring. I would use the native Time Machine to make a full, current backup of your device before attempting to reinstall your macOS.
Reinstalling macOS differs between Intel and silicon Macs;
For Intel Macs, switch off, restart while holding the R key until you see the Apple Icon or Command + R key on some older Macs.
To launch macOS Recovery on an Apple Silicon Mac, ensure the device is completely powered off. Press and hold the power button until the "Loading startup options" message or the Options icon appears on the screen, then release the button. Click the Options icon and select Continue to enter Recovery.
Once in Recovery you will see Reinstall macOS as one of the options, click that. It only reinstalls the elements of the operating system, your settings and personal data will not be effected.
Having said that it may not fix the problem if it is related to installed third party apps or hardware faults.