It looks like it should work, but you will get repeating widgets. That’s just because the random index can choose the same one several times on the trot.
If you want it to be ‘non-repeating random’, then you’ll need more code, to keep track of which widgets have been used.
The script looks fine. Which part does not work? The script is not triggerred? The widget is not added to the viewport / is not visible? The randomisation produces incorrect reaults?