In the bedrock version of the game it is possible to do:
/scoreboard players random <target> <objective> <min> <max>
This will give a random score between the set min and max to all the entities targeted by the selector. The score is random for each entity. This feature is currently missing from java.
It would be great if java got this feature as well as it would make doing random things easier and with less code.