Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
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
Иван Кубота
kus-admin
Commits
d44ffc72
Commit
d44ffc72
authored
Jan 16, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
seeded random
parent
cb8fbdcd
Pipeline
#515
canceled with stage
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
6 deletions
+52
-6
index.html
index.html
+2
-0
quizGenerator.js
public/js/controller/quizGenerator.js
+4
-4
rand.js
public/js/helpers/rand.js
+27
-0
generate.js
public/js/view/page/generate.js
+15
-2
main.css
public/main.css
+4
-0
No files found.
index.html
View file @
d44ffc72
...
...
@@ -10,6 +10,8 @@
<script
src=
"js/csv.js"
></script>
<script
src=
"js/helpers/rand.js"
></script>
<script
src=
"js/model/store.js"
></script>
<script
src=
"js/model/data.js"
></script>
...
...
public/js/controller/quizGenerator.js
View file @
d44ffc72
const
lapk
=
(
text
)
=>
`„
${
text
}
“`
;
const
rand
=
function
(
a
,
b
){
if
(
Array
.
isArray
(
a
)){
return
a
[
Math
.
random
()
*
a
.
length
|
0
];
return
a
[
Math
.
random
.
seeded
()
*
a
.
length
|
0
];
}
if
(
typeof
a
===
'object'
&&
'max'
in
a
){
b
=
a
.
max
;
...
...
@@ -9,7 +9,7 @@ const rand = function(a, b){
}
a
=
Math
.
ceil
(
a
);
b
=
Math
.
floor
(
b
);
return
Math
.
floor
(
Math
.
random
()
*
(
b
-
a
+
1
))
+
a
;
return
Math
.
floor
(
Math
.
random
.
seeded
()
*
(
b
-
a
+
1
))
+
a
;
return
(
r
-
a
)
*
(
b
-
a
)
|
0
;
},
...
...
@@ -19,7 +19,7 @@ const rand = function(a, b){
const
item
=
items
[
i
];
sum
+=
item
.
probability
|
0
;
}
const
theRandom
=
Math
.
random
();
const
theRandom
=
Math
.
random
.
seeded
();
let
total
=
0
;
for
(
let
i
=
0
,
_i
=
items
.
length
;
i
<
_i
;
i
++
){
...
...
@@ -46,7 +46,7 @@ const quizTypes = {
};
const
shuffle
=
function
(
a
)
{
for
(
let
i
=
a
.
length
-
1
;
i
>
0
;
i
--
)
{
const
j
=
Math
.
floor
(
Math
.
random
()
*
(
i
+
1
));
const
j
=
Math
.
floor
(
Math
.
random
.
seeded
()
*
(
i
+
1
));
[
a
[
i
],
a
[
j
]]
=
[
a
[
j
],
a
[
i
]];
}
return
a
;
...
...
public/js/helpers/rand.js
0 → 100644
View file @
d44ffc72
function
mulberry32
(
a
)
{
var
out
=
function
()
{
var
t
=
a
+=
0x6D2B79F5
;
t
=
Math
.
imul
(
t
^
t
>>>
15
,
t
|
1
);
t
^=
t
+
Math
.
imul
(
t
^
t
>>>
7
,
t
|
61
);
return
((
t
^
t
>>>
14
)
>>>
0
)
/
4294967296
;
}
out
.
getSeed
=
function
()
{
return
a
;
};
out
.
setSeed
=
function
(
A
)
{
a
=
A
;
};
out
.
setStringSeed
=
function
(
str
)
{
str
=
str
.
replace
(
/
[^
0-9a-z
]
/g
,
''
);
if
(
str
.
length
===
0
)
str
=
'1'
;
a
=
parseInt
(
str
,
36
);
};
out
.
getStringSeed
=
function
()
{
return
a
.
toString
(
36
);
};
return
out
;
}
Math
.
random
.
seeded
=
mulberry32
(
Math
.
floor
(
Math
.
random
()
*
4294967296
));
\ No newline at end of file
public/js/view/page/generate.js
View file @
d44ffc72
...
...
@@ -14,6 +14,8 @@ view.page.Generate = function() {
type
=
store
.
get
(
'generateType'
);
try
{
seedInput
.
value
=
Math
.
random
.
seeded
.
getStringSeed
();
const
result
=
quizGenerator
(
type
,
photo
);
title
.
innerHTML
=
textFormat
(
result
.
question
,
true
);
...
...
@@ -26,7 +28,8 @@ view.page.Generate = function() {
}
};
let
title
,
answers
,
debug
;
let
title
,
answers
,
debug
,
seedInput
,
setSeed
;
this
.
dom
=
div
({
cls
:
'generate-panel'
},
div
({
cls
:
'title-gradient'
},
...
...
@@ -45,7 +48,17 @@ view.page.Generate = function() {
div
({
cls
:
'generate-controls'
},
D
.
input
({
attr
:
{
type
:
'button'
,
value
:
'F5'
},
on
:
{
click
:
update
}})),
on
:
{
click
:
update
}}),
span
({
cls
:
'generate-seed-label'
},
'Seed:'
),
seedInput
=
D
.
input
({
cls
:
'seed'
,
attr
:
{
type
:
'input'
,
value
:
''
,
placeholder
:
'seed'
},
on
:
{
change
:
function
()
{
Math
.
random
.
seeded
.
setStringSeed
(
seedInput
.
value
);
}}}),
),
div
({
cls
:
'generate-example'
},
title
=
div
({
cls
:
'generate-title'
}),
...
...
public/main.css
View file @
d44ffc72
...
...
@@ -226,3 +226,6 @@ textarea.generate-debug {
.generate-controls
{
margin
:
16px
}
.generate-seed-label
{
margin
:
0
8px
0
32px
}
\ No newline at end of file
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