Newsgroups: comp.lang.javascript
From: Johannes Baagoe <baa...@baagoe.com>
Date: Thu, 25 Jun 2009 17:47:00 -0500
Subject: Re: Math.random
Johannes Baagoe :
> I shall give it an attempt, though, in another post. Here it is: introducing the Random object. Comments are welcome. Synopsis : var r = new Random(seed1, seed2, ...); The constructor may be called with any number of seeds of any kind - You may, for instance, write things like r = new Random( which should make it rather unlikely that two users ever generate the same new Random() with no arguments is equivalent to new Random(new Date()), Other methods : reSeed(seed1, seed2, ...) alters the existing state by combining it with getState() returns the internal state of the generator, to allow replays. setState(state) resets the generator to a state saved with getState(). Code : function Random() { var hash = 31415; function kiss32() { y ^= y << 13; var t = z + w + c; return x + y + w >>> 0; this.random = function() { this.reSeed = function() { if (arguments.length === 0) { for (i = 0; i < arguments.length; i++) { if (arg instanceof Date) { for (i = seed.length - 1; i >= 0; i--) { if (y == 0) { c ^= z >>> 31; w &= 0x7fffffff; this.getState = function() { this.setState = function(state) { this.reSeed.apply(this, arguments); } WARNING : I know next to nothing about cross-browser issues, I don't usually write for the World Wide Web. E.g., in reSeed, I assume that if Event is defined and something is an instanceof Event, that something is indeed a DOM event whose properties may be implicitly converted to Strings and concatenated in a for ... in statement, and that the resulting string will indeed contain at least a timestamp with a theoretical millisecond resolution, the mouse coordinates in the case of mouse events, the key involved in the case of key events, etc. For all I know, these could be wild assumptions in some browsers. Feedback on such and other issues would be much appreciated. -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||