You can wrap the variable declaration into a mixin and it will be evaluated only once, e.g.:
.constRandom() {
@randomNum: `Math.ceil(Math.random() * 100000)`;
} .constRandom();
div#div1{
background: url("/assets/img/core/ui/document-flexpaper-sprite.png?lm=@{randomNum}");
}
div#div2{
background: url("/assets/img/core/ui/document-flexpaper-sprite.png?lm=@{randomNum}");
}