如何使用JavaScript返回0到199之间的随机数?

要返回0到199之间的随机数,请使用JavaScript Math.random()和Math.floor()方法。

示例

您可以尝试运行以下代码以在JavaScript中返回随机数。

<!DOCTYPE html>
<html>
   <body>
      <script>
         document.write(Math.floor(Math.random() * 200));
      </script>
   </body>
</html>