天天看点

JAVA库函数总结【持续更新】

生成随机数:

Math.random()是令系统随机选取大于等于 0.0 且小于 1.0 的伪随机 double 值.

Random rand = newRandom();

rand.nextInt(int s);//生成0~s内的整数

int randNumber =rand.nextInt(MAX - MIN + 1) + MIN;//生成指定范围的整数

关于web服务获取服务器ip、hostname:

1.

string ip = Request.ServerVariables["Remote_Addr"];

string ip = Request.UserHostAddress;

2.

InetAddress addr = InetAddress.getLocalHost();

ip=addr.getHostAddress().toString;//获得本机IP

address=addr.getHostName()toString;//获得本机名称