Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
Lottery
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
十年打工还是工,梭哈一夜往皇宫
Lottery
Commits
62bdbf88
Commit
62bdbf88
authored
Oct 24, 2019
by
十年打工还是工,梭哈一夜往皇宫
🤡
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'caiweiguo/Lottery-master' into 'master'
Caiweiguo/lottery master See merge request
!14
parents
e08b9f48
f73e5c7e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
2 deletions
+55
-2
Program.cs
Lottery/Lottery/Program.cs
+33
-2
RandomOrg.cs
Lottery/Lottery/RandomOrg.cs
+22
-0
No files found.
Lottery/Lottery/Program.cs
View file @
62bdbf88
...
@@ -43,7 +43,9 @@ namespace Lottery
...
@@ -43,7 +43,9 @@ namespace Lottery
//开始计分,该循环表示计分规则
//开始计分,该循环表示计分规则
//获取从www.random.org生成的真随机数
//获取从www.random.org生成的真随机数
IReadOnlyList
<
int
>
randoms
=
RandomOrg
.
GetRandomsAsync
(
persons
.
Count
).
Result
;
IReadOnlyList
<
int
>
randoms
=
RandomOrg
.
GetRandomsAsync
(
persons
.
Count
).
Result
;
for
(
int
j
=
0
;
j
<
persons
.
Count
;
j
++)
//生成人员排序随机数
IReadOnlyList
<
int
>
indexRandoms
=
RandomOrg
.
GetIntRandomsAsync
(
persons
.
Count
).
Result
;
if
(
indexRandoms
!=
null
)
{
{
//计分方式1:根据返回的随机数加金币
//计分方式1:根据返回的随机数加金币
//计分方式2:看命
//计分方式2:看命
...
@@ -55,10 +57,39 @@ namespace Lottery
...
@@ -55,10 +57,39 @@ namespace Lottery
if
(
i
==
3
&&
persons
[
j
].
BaseGrade
>
0
)
if
(
i
==
3
&&
persons
[
j
].
BaseGrade
>
0
)
{
{
persons
[
j
].
NewGrade
+=
Person
.
GetRandomBaseGrade
(
persons
[
j
].
BaseGrade
);
//计分方式1:根据返回的随机数加金币
//计分方式2:看命
//计分方式3:随即加上一个人的金币,看能否逆袭
//其他方式:可在下方对NewGrade属性进行操作
int
index
=
indexRandoms
[
j
];
persons
[
j
].
NewGrade
+=
(
randoms
[
index
]
+
(
Math
.
Abs
(
persons
[
index
].
GetHashCode
()
<<
1
)
%
persons
.
Count
)
+
persons
[
randoms
[
index
]
-
1
].
OldGrade
);
if
(
i
==
3
&&
persons
[
index
].
BaseGrade
>
0
)
{
persons
[
index
].
NewGrade
+=
Person
.
GetRandomBaseGrade
(
persons
[
index
].
BaseGrade
);
}
}
}
}
}
else
{
for
(
int
j
=
0
;
j
<
persons
.
Count
;
j
++)
{
//计分方式1:根据返回的随机数加金币
//计分方式2:看命
//计分方式3:随即加上一个人的金币,看能否逆袭
//其他方式:可在下方对NewGrade属性进行操作
persons
[
j
].
NewGrade
+=
(
randoms
[
j
]
+
(
Math
.
Abs
(
persons
[
j
].
GetHashCode
()
<<
1
)
%
persons
.
Count
)
+
persons
[
randoms
[
j
]
-
1
].
OldGrade
);
if
(
i
==
3
&&
persons
[
j
].
BaseGrade
>
0
)
{
persons
[
j
].
NewGrade
+=
Person
.
GetRandomBaseGrade
(
persons
[
j
].
BaseGrade
);
}
}
}
//计分结束,以下为保存及更新显示
//计分结束,以下为保存及更新显示
Console
.
Clear
();
Console
.
Clear
();
Screen
.
ShowTitle
(
"第"
+
i
.
ToString
()
+
"轮"
);
Screen
.
ShowTitle
(
"第"
+
i
.
ToString
()
+
"轮"
);
...
...
Lottery/Lottery/RandomOrg.cs
View file @
62bdbf88
...
@@ -37,6 +37,28 @@ namespace Lottery
...
@@ -37,6 +37,28 @@ namespace Lottery
catch
(
Exception
)
catch
(
Exception
)
{
{
}
var
r
=
new
Random
(
length
);
return
Enumerable
.
Range
(
0
,
length
).
Select
(
p
=>
r
.
Next
(
1
,
length
+
1
)).
ToList
();
}
public
static
async
Task
<
IReadOnlyList
<
int
>>
GetIntRandomsAsync
(
int
length
)
{
try
{
using
(
HttpClient
httpClient
=
new
HttpClient
())
{
httpClient
.
DefaultRequestHeaders
.
TryAddWithoutValidation
(
"user-agent"
,
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3936.0 Safari/537.36 Edg/79.0.301.2"
);
var
resp
=
await
httpClient
.
GetAsync
(
$"https://www.random.org/integer-sets/?sets=1&num=
{
length
}
&min=0&max=
{
length
-
1
}
&commas=on&order=random&format=plain&rnd=new"
);
if
(
resp
.
IsSuccessStatusCode
)
{
string
content
=
await
resp
.
Content
.
ReadAsStringAsync
();
return
content
.
Split
(
','
).
Where
(
p
=>
!
string
.
IsNullOrEmpty
(
p
)).
Select
(
p
=>
int
.
Parse
(
p
)).
ToList
();
}
}
}
catch
(
Exception
)
{
}
}
var
r
=
new
Random
(
length
);
var
r
=
new
Random
(
length
);
return
Enumerable
.
Range
(
0
,
length
).
Select
(
p
=>
r
.
Next
(
1
,
length
+
1
)).
ToList
();
return
Enumerable
.
Range
(
0
,
length
).
Select
(
p
=>
r
.
Next
(
1
,
length
+
1
)).
ToList
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment