zoukankan
html css js c++ java
抽牌式随机数序列
Code
1
/**/
///
<summary>
2
///
生成4位随机数
3
///
</summary>
4
public
class
RandomNumber
5
{
6
private
static
int
[] numberList;
7
private
static
RandomNumber randomNumber;
8
private
RandomNumber()
9
{
10
numberList
=
new
int
[
9000
];
11
for
(
int
i
=
0
; i
<
9000
; i
++
)
12
{
13
numberList[i]
=
(i
+
1000
);
14
}
15
}
16
public
static
RandomNumber Run()
17
{
18
if
(randomNumber
==
null
||
numberList
==
null
)
19
{
20
randomNumber
=
new
RandomNumber();
21
}
22
return
randomNumber;
23
}
24
25
private
static
int
index
=
8999
;
26
public
int
GetRandomNumber()
27
{
28
Random rnd
=
new
Random(
unchecked
((
int
)DateTime.Now.Ticks));
29
30
int
i
=
rnd.Next(
0
, index
+
1
);
//
抽取的序列号
31
32
int
r
=
numberList[i];
33
34
int
t
=
numberList[index];
35
numberList[index]
=
numberList[i];
36
numberList[i]
=
t;
37
38
index
--
;
39
if
(index
<=
0
)
40
{
41
index
=
8999
;
42
}
43
return
r;
44
}
45
46
只是为了防止重复出现而已... 但是还是会有重复的出现..囧..
原因在web上如果同时N个人运行到此程序,则有可能出现相同的数字
查看全文
相关阅读:
Annotation
injector
Java容器(container)
build tool(构建工具)maven和gradle安装方法
version control(版本控制)
函数式编程
URI与URL
超文本传输协议HTTP
annotation的理解
Injection
原文地址:https://www.cnblogs.com/Zoya/p/1553497.html
最新文章
rgba
关于border-radius的个人理解
js制作tab选项卡
函数式编程语言
HTTP解析
deployment、discriptor、web.xml
annotation
Container,Injection
buildtools
Version Control System
热门文章
函数编程语言
URL与URI的不同
HTTP的RFC解析
关于JSF
什么是Annotation
Git的相关知识
building tool的简单了解
HTTP和RFC
URL和URI以及两者的区别和联系
function Language
Copyright © 2011-2022 走看看