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
4391dbdc
Commit
4391dbdc
authored
Oct 22, 2019
by
caiwg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加人员随机排序
parent
cb67e02d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
1 deletion
+45
-1
Program.cs
Lottery/Lottery/Program.cs
+24
-1
RandomOrg.cs
Lottery/Lottery/RandomOrg.cs
+21
-0
No files found.
Lottery/Lottery/Program.cs
View file @
4391dbdc
...
...
@@ -43,6 +43,29 @@ namespace Lottery
//开始计分,该循环表示计分规则
//获取从www.random.org生成的真随机数
IReadOnlyList
<
int
>
randoms
=
RandomOrg
.
GetRandomsAsync
(
persons
.
Count
).
Result
;
//生成人员排序随机数
IReadOnlyList
<
int
>
indexRandoms
=
RandomOrg
.
GetIntRandomsAsync
(
persons
.
Count
).
Result
;
if
(
indexRandoms
!=
null
)
{
for
(
int
j
=
0
;
j
<
indexRandoms
.
Count
;
j
++)
{
//计分方式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:根据返回的随机数加金币
...
...
@@ -58,7 +81,7 @@ namespace Lottery
persons
[
j
].
NewGrade
+=
Person
.
GetRandomBaseGrade
(
persons
[
j
].
BaseGrade
);
}
}
}
//计分结束,以下为保存及更新显示
Console
.
Clear
();
Screen
.
ShowTitle
(
"第"
+
i
.
ToString
()
+
"轮"
);
...
...
Lottery/Lottery/RandomOrg.cs
View file @
4391dbdc
...
...
@@ -41,5 +41,26 @@ namespace Lottery
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=1&max=
{
length
}
&commas=on&order=random&format=html&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
)
{
}
return
null
;
}
}
}
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