This question has been asked a couple of times, but never exactly how I need it. I'm trying to do something like this: I have a fixed number of spans and I want to give every one of them a font size between 10px and 46px. Some can have the same value! Decimals are allowed (but I'm guessing useless because browsers handle "sub-pixels" differently (I am told)). Apart from that, I want a random value between 0 and 100 for left and top properties, but these values can never be the same!
I got this far: (borrowed from here on SO), but sometimes values overlap.
function randomFromInterval(from,to) { return Math.floor(Math.random()*(to-from+1)+from); } $("#question-mark-wrapper > span:not('.the-one')").each(function() { $(this).css({ "font-size": randomFromInterval(10,36) + "px", // Can be the same value twice "left": randomFromInterval(0,100) + "%", // Cannot be the same value twice "top": randomFromInterval(0,100) + "%", // Cannot be the same value twice }); });