As @AlexandreNeto mentioned, you could create a custom python function in the Field Calculator which creates a range list of values based on the feature count of your active layer. The list is then shuffled and you can extract a unique id value randomly.
You could use something like the following script:
from qgis.core import *
from qgis.gui import *
import random
layer = qgis.utils.iface.activeLayer()
ids = list(range(1, layer.featureCount() + 1))
random.shuffle(ids)
@qgsfunction(args='auto', group='Custom')
def random_id(value, feature, parent):
return ids[value]
And then use the following as the expression:
random_id($id)
Note: You must click the Save and Load Functions
button in the Function Editor before using it on other layers. This is because defining the active layer and creating the list of unique values based on its features count is outside the function in order to avoid re-creating the list each time for each row.
array_get(array_distinct(array_agg (rand(0, count($id)))), $id)