This does the trick, just tested it out. You will just have to convert the Xpath values and you should be good to go.
var temp = Math.random() * 10;
var random = 0;
if (temp >= 0 && temp <= 4)
{
random = (Math.round(Math.random() * 10)) % 2;
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = random;
}
else if (temp > 4 && temp <= 6.5)
{
random = ((Math.round(Math.random() * 10)) % 2) + 2;
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = random;
}
else if (temp > 6.5 && temp <= 8)
{
random = ((Math.round(Math.random() * 10)) % 2) + 4;
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = random;
}
else if (temp > 8 && temp <= 9)
{
random = ((Math.round(Math.random() * 10)) % 2) + 6;
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = random;
}
else if (temp > 9 && temp <= 9.8)
{
random = ((Math.round(Math.random() * 10)) % 2) + 8;
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = random;
}
else if (temp > 9.8 && temp <= 10)
{
random = 10;
XDocument.DOM.selectSingleNode("/my:myFields/my:field1").text = random;
}