Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
belenios
belenios
Commits
40c74209
Commit
40c74209
authored
Jun 02, 2014
by
Stephane Glondu
Browse files
Fix random number generation
Words and strings were mixed up...
parent
d7ea3174
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/platform/js/platform.ml
View file @
40c74209
...
...
@@ -73,12 +73,23 @@ let secure_rng () =
let
pseudo_rng
x
()
=
()
let
string_of_hex
hex
n
=
let
res
=
String
.
create
n
in
for
i
=
0
to
n
-
1
do
let
c
=
int_of_string
(
"0x"
^
String
.
sub
hex
(
2
*
i
)
2
)
in
res
.
[
i
]
<-
char_of_int
c
done
;
res
let
random_string
rng
n
=
let
()
=
rng
()
in
Js
.
Unsafe
.
meth_call
sjcl_random
"randomWords"
[
|
n
|>
float_of_int
|>
Js
.
number_of_float
|>
Js
.
Unsafe
.
inject
;
|
]
|>
Js
.
to_string
let
words
=
Js
.
Unsafe
.
meth_call
sjcl_random
"randomWords"
[
|
n
/
4
+
1
|>
float_of_int
|>
Js
.
number_of_float
|>
Js
.
Unsafe
.
inject
|
]
in
let
hex_words
=
Js
.
Unsafe
.
meth_call
sjcl
"codec.hex.fromBits"
[
|
words
|
]
|>
Js
.
to_string
in
string_of_hex
hex_words
n
module
Z
=
struct
open
Js
.
Unsafe
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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