Random Number Generator for HTML?

I am looking for a HTML code that can generate a single random number between (and including) 1 and 38 and assign it to a variable. (I'm calling that variable "ran")

I would really appreciate any help.

2008-02-15T16:56:35Z

I was talking about generating random numbers within a SCRIPT tag. I'm trying to make the webpage play a random song and I have everything working properly except the random number generator. The code I'm using does seem to have access to all the possible choices.

2008-02-15T17:03:15Z

When I inserted J P's code,

var randNum = Math.ceil(Math.random()*10);

it seems to work. I have one question. Does the number range include the endpoints?

J P2008-02-15T16:09:35Z

Favorite Answer

HTML is really not capable of generating random numbers. You can use a simple bit of Javascript to generate one, however. You can use:
<script type="text/javascript">
var randNum = Math.ceil(Math.random()*10);
</script>
to generate a random number between 1 and 10, if you need a different range, you can change the 10 above to whatever you want the upper bound to be.

Anonymous2016-12-18T09:09:53Z

Random Number Generator Html Code

?2016-03-13T05:45:28Z

I want to create two three digit number generators where the value of both generators will never be same in html....

Anonymous2008-02-15T16:08:42Z

HTML is a content descriptor, not a programming language. You'll have to use javascript (client side) or something like php (server side) to do that. You also can't "assign variables" in html - strictly speaking, there are none.