Re: [Flightgear-devel] Repeatable random seeds

2011-09-16 Thread Andreas Gaeb
Am 15.09.2011 22:24, schrieb Stuart Buchanan:
[...]
 This is a bit trickier to fix in concept, because we want there to be 
 variation
 in the clouds between runs rather than generating exactly the same set
 of clouds if you start in the same location with the same weather.
yes, this is very desirable.

 [...]
 Unfortunately that will differ if a METAR update takes place between the
 different FG instances being started. Perhaps those running multiple FG
 instances on different machines could comment on whether this restriction
 would be acceptable?
Up to now, I have been running without real weather fetch, so METAR 
updates are no problem at all. For the project here, we'll probably only 
need to use fixed weather scenarios.

However, the sg_srandom_time_10() function also looks appealing. That 
would give the same random seed for all processes started within the 
same 10 minute interval, yet also vary every 10 minutes even with the 
same METAR. Maybe even METAR updates are possible if an update re-seeds 
from that function.

Best regards,
Andreas


--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Repeatable random seeds

2011-09-16 Thread Csaba Halász
On Fri, Sep 16, 2011 at 10:35 AM, Andreas Gaeb a.g...@web.de wrote:

 However, the sg_srandom_time_10() function also looks appealing. That
 would give the same random seed for all processes started within the
 same 10 minute interval, yet also vary every 10 minutes even with the
 same METAR. Maybe even METAR updates are possible if an update re-seeds
 from that function.

Ideally, we want MP to be synchronized too, and also if you restart FG
on one of the machines it should pick up the same random stream again.

-- 
Csaba/Jester

--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Repeatable random seeds

2011-09-16 Thread Erik Hofman
On Fri, 2011-09-16 at 13:22 +0200, Csaba Halász wrote:
 On Fri, Sep 16, 2011 at 10:35 AM, Andreas Gaeb a.g...@web.de wrote:
 
  However, the sg_srandom_time_10() function also looks appealing. That
  would give the same random seed for all processes started within the
  same 10 minute interval, yet also vary every 10 minutes even with the
  same METAR. Maybe even METAR updates are possible if an update re-seeds
  from that function.
 
 Ideally, we want MP to be synchronized too, and also if you restart FG
 on one of the machines it should pick up the same random stream again.

sg_srandom_time_10() divides the time in chunks of 10 minutes, so if
there is a mismatch the first time it will get corrected the next time.

Erik


--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


[Flightgear-devel] Repeatable random seeds

2011-09-14 Thread Andreas Gaeb

Hello everybody,

lately I've been working on a multiscreen setup driven by multiple host 
machines. In order to get the same random scenery objects, all machines 
need to use the same random seed. Up to now, the random seed is taken 
from system time, which leads to inconsistencies.


The attached patches add a command line option --random-seed=int, 
which allows to explicitly specify a (positive) seed, or -1 (the default 
when the option is not given) to seed from system time, or -2 to seed 
from system time in 10 minutes intervals.


This is however only a first step, there are remaining inconsistencies, 
most prominently 3D clouds differ, even between two runs on the same 
machine. I suspect this is because there is only one instance of the 
random number generator, which may be accessed in non-deterministic 
order from different threads. The solution is probably to make a random 
number stream class, of which each relevant subsystem/class/whatever 
keeps its own static instance. I'll be looking further into this, but 
maybe someone has some experience on this to share?


Best regards,
Andreas
commit a217c57fc723ce88397295cfda0eff2eb9071ad3
Author: Andreas Gaeb a.g...@web.de
Date:   Wed Sep 7 20:14:54 2011 +0200

added command line option to specify random seed

diff --git a/scripts/completion/fg-completion.bash b/scripts/completion/fg-completion.bash
index 4f34e2d..464fefa 100644
--- a/scripts/completion/fg-completion.bash
+++ b/scripts/completion/fg-completion.bash
@@ -28,6 +28,7 @@ __fgfs_options=
 	--enable-intro-music
 	--units-feet
 	--units-meters
+	--random-seed=
 	--disable-sound
 	--enable-sound
 	--disable-panel
diff --git a/scripts/completion/fg-completion.zsh b/scripts/completion/fg-completion.zsh
index f4cda35..08309e0 100644
--- a/scripts/completion/fg-completion.zsh
+++ b/scripts/completion/fg-completion.zsh
@@ -103,6 +103,7 @@ _fgfs_options=(
 	'--aero=[Select aircraft aerodynamics model to load]' \
 	'--model-hz=[Run the FDM this rate (iterations per second)]' \
 	'--speed=[Run the FDM n times faster than real time]' \
+	'--random-seed=[Specify value for random seed]' \
 	'--aircraft-dir=[Aircraft directory relative to the path of the executable]:Aircraft directory:_directories' \
 	'--timeofday=[Specify a time of day]:Time of day:(real dawn morning noon afternoon dusk evening midnight)' \
 	'--time-offset=[Add this time offset (+/-hh:mm:ss)]' \
diff --git a/src/Main/main.cxx b/src/Main/main.cxx
index 6fa94dc..f457204 100644
--- a/src/Main/main.cxx
+++ b/src/Main/main.cxx
@@ -595,9 +595,6 @@ int fgMainInit( int argc, char **argv ) {

 globals = new FGGlobals;

-// seed the random number generator
-sg_srandom_time();
-
 FGControls *controls = new FGControls;
 globals-set_controls( controls );

@@ -642,6 +639,19 @@ int fgMainInit( int argc, char **argv ) {
 exit(-1);
 }

+// seed the random number generator
+int seed = fgGetInt(/sim/random-seed, -1);
+if (seed  -2) {
+  SG_LOG( SG_GENERAL, SG_ALERT, Random seed must be = -2. Will use system time as random seed.);
+  sg_srandom_time();
+} else if (seed == -2) {
+  sg_srandom_time_10();
+} else if (seed == -1) {
+  sg_srandom_time();
+} else {
+  sg_srandom(seed);
+}
+
 // Initialize the Window/Graphics environment.
 fgOSInit(argc, argv);
 _bootstrap_OSInit++;
diff --git a/src/Main/options.cxx b/src/Main/options.cxx
index 172d133..7bb0601 100644
--- a/src/Main/options.cxx
+++ b/src/Main/options.cxx
@@ -1374,6 +1374,7 @@ struct OptionDesc {
 {aircraft-dir, true,  OPTION_STRING, /sim/aircraft-dir, false, , 0 },
 {model-hz, true,  OPTION_INT,/sim/model-hz, false, , 0 },
 {speed,true,  OPTION_INT,/sim/speed-up, false, , 0 },
+{random-seed,  true,  OPTION_INT,/sim/random-seed, false, , 0 },
 {trim, false, OPTION_BOOL,   /sim/presets/trim, true, , 0 },
 {notrim,   false, OPTION_BOOL,   /sim/presets/trim, false, , 0 },
 {on-ground,false, OPTION_BOOL,   /sim/presets/onground, true, , 0 },
commit 9c84f590ecef747714d598635938f2e22a441a84
Author: Andreas Gaeb a.g...@web.de
Date:   Fri Sep 9 10:33:58 2011 +0200

--random-seed option added to help

diff --git a/Translations/strings-default.xml b/Translations/strings-default.xml
index e689a26..3f6f339 100644
--- a/Translations/strings-default.xml
+++ b/Translations/strings-default.xml
@@ -116,6 +116,7 @@
  config-descLoad additional properties from path/config-desc
  units-feet-descUse feet for distances/units-feet-desc
  units-meters-descUse meters for distances/units-meters-desc
+ random-seed-descUse value as repeatable random seed. Value=-1 seeds from system time, value=-2 from system time in 10 minute intervals/random-seed-desc
 
  !-- Features options --
  environment-optionsEnvironment 

Re: [Flightgear-devel] Repeatable random seeds

2011-09-14 Thread Erik Hofman
On Wed, 2011-09-14 at 11:18 +0200, Andreas Gaeb wrote:
 Hello everybody,
 
 lately I've been working on a multiscreen setup driven by multiple host 
 machines. In order to get the same random scenery objects, all machines 
 need to use the same random seed. Up to now, the random seed is taken 
 from system time, which leads to inconsistencies.

Is this broken.. again?
Sigh.

I've been pushing this behavior various times and scenery objects should
always be positioned at the same location over and over again.

This has been fixed a number of times with a proper solution.
This patch is not a proper solution, sorry.

Erik


--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerryreg; mobile platform with sessions, labs  more.
See new tools and technologies. Register for BlackBerryreg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Repeatable random seeds

2011-09-14 Thread Stuart Buchanan
On Wed, Sep 14, 2011 at 10:43 AM, Erik Hofman wrote:
 Is this broken.. again?
 Sigh.

 I've been pushing this behavior various times and scenery objects should
 always be positioned at the same location over and over again.

This may just be broken in the default 3D clouds code. I'll take a look. I know
how to fix it properly ;)

Thorsten Renk - If this something we need to be thinking about for the Local
Weather as well?

-Stuart

--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerryreg; mobile platform with sessions, labs  more.
See new tools and technologies. Register for BlackBerryreg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Repeatable random seeds

2011-09-14 Thread thorsten . i . renk
 Thorsten Renk - If this something we need to be thinking about for the
 Local Weather as well?

We've been tossing the idea around in the forum that Local Weather stops
using the rand() function from Nasal and uses its own internal random
number generator. In this way, it could be initialized in a well-defined
state on different machines, the sequence could not be messed up by other
Nasal scripts running and you'd generate a predictable configuration.

I haven't done anything in that direction though...

* Thorsten


--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerryreg; mobile platform with sessions, labs  more.
See new tools and technologies. Register for BlackBerryreg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Repeatable random seeds

2011-09-14 Thread Stuart Buchanan
On Wed, Sep 14, 2011 at 11:18 AM,  Thorsten Renk wrote:
 Thorsten Renk - If this something we need to be thinking about for the
 Local Weather as well?

 We've been tossing the idea around in the forum that Local Weather stops
 using the rand() function from Nasal and uses its own internal random
 number generator. In this way, it could be initialized in a well-defined
 state on different machines, the sequence could not be messed up by other
 Nasal scripts running and you'd generate a predictable configuration.

 I haven't done anything in that direction though...

OK. We've got something similar already in the C code for exactly this
purpose. Might be more efficient to simply expose that over Nasal, but
I'm not sure how easy that would actually be.

-Stuart

--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerryreg; mobile platform with sessions, labs  more.
See new tools and technologies. Register for BlackBerryreg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Repeatable random seeds

2011-09-14 Thread Erik Hofman
On Wed, 2011-09-14 at 13:33 +0200, Andreas Gaeb wrote:
 Am 14.09.2011 11:43, schrieb Erik Hofman:
  I've been pushing this behavior various times and scenery objects should
  always be positioned at the same location over and over again.
 To clarify things up a bit, not all is broken:
 - Houses etc. are the same
 - Trees are at the same location and same size, but sometimes have 
 different textures. Looks like this is called by a rand() call in 
 TreeBin.cxx:256, which is probably there because sg_random doesn't have 
 an integer rand function.
 - both 2D and 3D clouds differ, and as far as I can tell, both in 
 position and texture.

Ah ok, then I guess it's better to address those different items instead
of trying to create a reproducible wind gust (for instance) ;-)

Erik


--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerryreg; mobile platform with sessions, labs  more.
See new tools and technologies. Register for BlackBerryreg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Repeatable random seeds

2011-09-14 Thread James Turner

On 14 Sep 2011, at 12:00, Stuart Buchanan wrote:

 OK. We've got something similar already in the C code for exactly this
 purpose. Might be more efficient to simply expose that over Nasal, but
 I'm not sure how easy that would actually be.

Pretty trivial, for a function such as sg_random, unless I'm missing something 
really subtle.

Basically add a f_random wrapper in NasalSys.cxx, add an entry to the static 
table at the bottom of the file, and you should be done. Oh, except you need to 
pick a name that doesn't clash with any internal Nasal rand/random.

James


--
BlackBerryreg; DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the 
BlackBerryreg; mobile platform with sessions, labs  more.
See new tools and technologies. Register for BlackBerryreg; DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1 
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel