Commit 8314c4cf authored by Thomas Marrinan's avatar Thomas Marrinan

updated random number generator - synced across multiple nodes


Former-commit-id: c6104d64032a48fe8b6b2de1c3ed5cc884e72516
parent 512039bb
......@@ -116,10 +116,13 @@
});
wsio.on('initialize', function(data) {
var startTime = new Date(data.start);
var serverTime = new Date(data.time);
var clientTime = new Date();
dt = clientTime - serverTime;
Math.seed(startTime.getTime());
});
wsio.on('setupDisplayConfiguration', function(json_cfg) {
......@@ -679,6 +682,20 @@
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
Math.seed = function(s) {
Math.random = function() {
// POSIX drand48 ==> Xn+1 = (a*Xn+c) % m
var a = 25214903917;
var c = 11;
var m = 281474976710656;
s = (a*s+c) % m;
return s / m;
//s = Math.sin(s) * 10000; return s - Math.floor(s);
}
};
</script>
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
......
......@@ -8,14 +8,6 @@
// http://opensource.org/licenses/BSD-3-Clause
// See included LICENSE.txt file
// New seeded Math.random function
Math.seed = function(s) {
Math.random = function() {
s = Math.sin(s) * 10000; return s - Math.floor(s);
}
};
var SAGE2_App = Class.extend( {
construct: function() {
this.div = null;
......@@ -48,8 +40,6 @@ var SAGE2_App = Class.extend( {
this.startDate = date;
this.prevDate = date;
this.frame = 0;
// Seed the number generator based on current time
Math.seed(date.getTime());
},
preDraw: function(date) {
......
......@@ -95,6 +95,8 @@ var options = setupHttpsOptions();
var index = http.createServer(httpServerIndex.onrequest);
var server = https.createServer(options, httpsServerApp.onrequest);
var startTime = new Date();
// creates a WebSocket server - 2 way communication between server and all browser clients
var wsioServer = new websocketIO.Server({server: server});
......@@ -177,7 +179,7 @@ function wsAddClient(wsio, data) {
function initializeWSClient(wsio) {
var uniqueID = wsio.remoteAddress.address + ":" + wsio.remoteAddress.port;
wsio.emit('initialize', {UID: uniqueID, time: new Date()});
wsio.emit('initialize', {UID: uniqueID, time: new Date(), start: startTime});
// set up listeners based on what the client sends
if(wsio.messages.sendsPointerData){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment