Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java random #780

Merged
merged 2 commits into from
Jun 29, 2014
Merged

Java random #780

merged 2 commits into from
Jun 29, 2014

Conversation

gzm0
Copy link
Contributor

@gzm0 gzm0 commented Jun 27, 2014

No description provided.

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 27, 2014

Review by @sjrd

// see nextGaussian()
private var nextNextGaussian: Double = _
private var haveNextNextGaussian: Boolean = false

def this(seed: Long) = this() // ignore seed
def this(seed_in: Long) = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this one the primary constructor, then. Otherwise the initialization of seed unnecessarily creates a random seed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the recommendation of member ordering there?

  1. vals
  2. primary ctor code
  3. ctors
  4. methods

???

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is usually the order I use, indeed.

@scala-jenkins
Copy link

Test FAILed.
Refer to this link for build results: https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/183/

(randomInt().toLong << 32) | (randomInt().toLong & 0xffffffffL)

private def randomInt(): Int =
(Math.floor(Math.random() * 4294967296.0) - 2147483648.0).toInt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh oh! Must be js.Math.random()! Otherwise this thing enters an infinite recursion, because Math.random() uses a java.util.Random created without seed, so with a random seed, which is created with randomInt(), which calls Math.random()...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't java.lang.Math shadowed by the import? (Importing scala.scala.js.Math is your madness :P)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Well, fix my madness, then.

@sjrd
Copy link
Member

sjrd commented Jun 27, 2014

That's all.

@sjrd
Copy link
Member

sjrd commented Jun 27, 2014

checksizes must be adapted.

@scala-jenkins
Copy link

Test FAILed.
Refer to this link for build results: https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/184/

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 27, 2014

This is bad: Reversi doesn't use Random, but the opt size nevertheless increases...

@sjrd
Copy link
Member

sjrd commented Jun 27, 2014

It might not use it directly. That does not mean some corner of the collection library isn't using random numbers for some non-obvious reason.

If you activate the DebugAnalyzer flag, you can track it down, if you want peace of mind.

@sjrd
Copy link
Member

sjrd commented Jun 27, 2014

Or simpler, remove the class altogether and look at the warnings emitted by fastOpt.

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 27, 2014

If I rename whole java.util.Random and remove Math.random, I can still fastOptJS reversi without any warnings...
I'll figure this out on Monday I suppose...

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 29, 2014

It's the initializer of the internalRandom and the bitmap for the lazy val.

--- master-fastopt.js   2014-06-29 22:40:31.086560212 +0200
+++ random-fastopt.js   2014-06-29 22:38:09.082565288 +0200
@@ -4221,8 +4221,10 @@
 /** @constructor */
 ScalaJS.c.jl_Math$ = (function() {
   ScalaJS.c.O.call(this);
+  this.internalRandom$1 = null;
   this.E$1 = 0.0;
-  this.PI$1 = 0.0
+  this.PI$1 = 0.0;
+  this.bitmap$0$1 = false
 });
 ScalaJS.c.jl_Math$.prototype = new ScalaJS.h.O();
 ScalaJS.c.jl_Math$.prototype.constructor = ScalaJS.c.jl_Math$;

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 29, 2014

Updated

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 29, 2014

Before merging, please verify that the change in size for 2.11.0 was justified (tested 2.11.1 only).

@scala-jenkins
Copy link

Test PASSed.
Refer to this link for build results: https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/185/

@gzm0
Copy link
Contributor Author

gzm0 commented Jun 29, 2014

Checksizes adaptation is justified for 2.11.0. You may go ahead and merge if LGTY.

@sjrd
Copy link
Member

sjrd commented Jun 29, 2014

LGTM :) Funny one, the change in size. ^^

sjrd added a commit that referenced this pull request Jun 29, 2014
@sjrd sjrd merged commit 3933e7c into scala-js:master Jun 29, 2014
@gzm0 gzm0 deleted the java-random branch June 29, 2014 21:09
@gzm0
Copy link
Contributor Author

gzm0 commented Jun 29, 2014

Yep... Cost me a good hour at least... :P

@scala-jenkins
Copy link

Test PASSed.
Refer to this link for build results: https://scala-webapps.epfl.ch/jenkins/job/scalajs-pr/186/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants