Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd20467

Browse files
author
zhourenjian@gmail.com
committed
Generate key use Math.random correctly or precisely random
1 parent24cd307 commitbd20467

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/CompoundPipeRunnable.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
publicclassCompoundPipeRunnableextendsSimplePipeRunnable {
44

55
privatestaticStringnextSessionKey() {
6-
StringhexStr ="0123456789abcdef";
7-
Stringkey ="";
6+
StringBufferkeyBuffer =newStringBuffer(4);
87
for (inti =0;i <4;i++) {
9-
inthex = (int)Math.round(15 *Math.random());
10-
key +="" +hexStr.charAt(hex);
8+
inthex = (int)Math.floor(Math.random() *16);
9+
keyBuffer.append((char) (hex <10 ? ('0' +hex) : ('a' +hex -10)));
1110
}
12-
returnkey;
11+
returnkeyBuffer.toString();
1312
}
1413

1514
CompoundPipeSession[]pipes;

‎sources/net.sf.j2s.ajax/ajaxpipe/net/sf/j2s/ajax/SimplePipeHelper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ synchronized static String registerPipe(SimplePipeRunnable pipe) {
120120
staticStringnextPipeKey() {
121121
StringBufferbuf =newStringBuffer(SimplePipeRequest.PIPE_KEY_LENGTH);
122122
for (inti =0;i <SimplePipeRequest.PIPE_KEY_LENGTH;i++) {
123-
intr = (int)Math.round((float)Math.random() *61);// 0..61, total 62 numbers
123+
intr = (int)Math.floor(Math.random() *62);// 0..61, total 62 numbers
124124
if (r <10) {
125125
buf.append((char) (r +'0'));
126126
}elseif (r <10 +26) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp