Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

why use Math.random() here ?

807589Aug 25 2008 — edited Sep 5 2008
<html>
<body>

<script type="text/javascript">
var r=Math.random();
if (r>0.5)
{
document.write("<a href='http://www.w3schools.com'>Learn Web Development!</a>");
}
else
{
document.write("<a href='http://www.refsnesdata.no'>Visit Refsnes Data!</a>");
}
</script>

</body>
</html>
In this code why we use Math.random().
When this generates no. between 0-<1

So If part can be correct and also possibility for else part is equal.
So what's importance of Math.random() here?

Thanks,
S.Singh
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2008
Added on Aug 25 2008
7 comments
103 views