Are you currently generating them in PsychoPy? I don’t know Prolific, but with Sona the software generates a completion code which is sent to Qualtrics/PsychoPy and then sent back again at the end, e.g.
https://app.prolific.co/submissions/complete?cc=I2PWSFRG
from https://researcher-help.prolific.co/hc/en-gb/articles/360009223173-Recording-participants-as-complete-on-Prolific
If you need to randomly assign a code within PsychoPy then I think you might need to experiment with this quote from my crib sheet:
Your final PsychoPy routine should include words along the lines of “Please wait for the message “Thank you for your patience” to appear and then click OK to continue the experiment”. The “Completed URL” can be formatted like a text element to include variables, e.g. “[https://brookeshls.co1.qualtrics.com/surveyname?expname="+$expName+"&participant=”+expInfo’participant’]. In Pavlovia expName is the file name for the PsychoPy file used to create the experiment. So long as you have URLs set in the experiment options, it may be possible to change them using the following command: PsychoJS.setRedirectUrls(myCompletedURL, myCancelledURL)
CompletedURL / IncompleteURL