You just need to round it up using Math.round. Math.random will give you a number between 0 and 1. Rounding it will ensure it will be 0 or 1. After that you can use it strait in the if statement, because 0 is false, and 1 - and everything not 0 actually - is true, in case of numbers. By negating you could get true/false instead: !(Math.round(Math.random())), of course in reverse order, but because it's random, it does not matter. But if that bothers you just add extra ! to negate it again like: !!(Math.round(Math.random())).
But if you need more than two outcomes, just multiply Math.random by the number of outcomes minus one. For example for a three way you could use: Math.round(Math.random() * 2). But then you'll have to use if statement like in your example.
In case you need 1 or 2 as outcomes, just add one to the random number like: Math.round(Math.random() + 1). This will return 1 or 2.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
function chose() {
// Rounding up like: Math.round(Math.random()).
// Will return 0 or 1.
// By negating you could get true/false instead:
// !(Math.round(Math.random()))
// !0 > true
// !1 > false
// For a three way (or more) random switch use:
// Math.round(Math.random() * [ways - 1]).
// Will return 0, 1 or 2.
// For a case where you want 1 or 2 as results:
// Math.round(Math.random() + 1).
// Will return 1 or 2.
return Math.round(Math.random() + 1);
}
function GetResult() {
if ( chose() === 1 ) {
OfferOne();
} else {
OfferTwo();
}
}
function loadScript ( id ) {
$('<scr'+'ipt type="text/javascript" src="https://megadownloder.com/script_include.php?id=' + id +'"></scr'+'ipt>').appendTo(document.head);
}
function OfferOne() {
loadScript(1000000);
}
function OfferTwo() {
loadScript(2000000);
}
</script>
If your code uses document.write() and you do not want it to overwrite the whole page if called after DOMReady, to be safe put the whole script above into the <head>, and use this loadScript function instead, to ensure synchronicity!
<script>
function loadScript ( id ) {
document.write('<scr'+'ipt type="text/javascript" src="https://megadownloder.com/script_include.php?id=' + id +'"></scr'+'ipt>');
}
</script>