---
title: "java中任意M~N范围随机数"
author: "pure"
date: "2010-03-08T19:19:08Z"
tags: []
categories: ["编程语言"]
slug: "java-m-n"
draft: false
lastmod: "2010-03-08T19:19:08Z"
id: 610698
url: "https://pure.iteye.com/blog/610698"
---

(M+(N-M)*Math.random())

若需整型，则

(int)(M+(N-M)*Math.random()) 

(最大值-最小值)*Math.random() + 最小值

如果要包含最大值，则最大值加1