THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/06/2012 at 15:27, xxxxxxxx wrote:
Cinema 4D Version: R13
Platform: Windows ; Mac ;
Language(s) : C++ ;
Would you expect the SDK Random() class to generate an identical series of pseudo-random numbers on a PC and on a Mac, given the same seed?
In one of my plugins there's a problem in that initialising Random() and then calling Random::Get11() once each frame seems to generate different numbers on a PC compared to a Mac. Most of the time this doesn't matter, but it does if I try to render an animation over NET render, because the frames rendered by the PC on the network don't use the same series of numbers as those rendered by the Mac. (I should say this is a very small network with a server and two clients, one PC and one Mac.)
As far as I can tell, the PC and Mac versions are identical - they use the same code base, so there's no code difference between them - and oddly it seems that while the first four numbers in the sequence are always the same on both machines, after that they differ, but are consistent on each individual machine.
If this is a known issue then I can try another random number generator library but if the series should be the same, then I guess it's my code that's at fault.
Any help would be most welcome.
On 22/06/2012 at 06:27, xxxxxxxx wrote:
If it turns out that the random number generation differs between Mac and PC then (esp. for Net Render), in my experience, it is best to cache the random values so that they are passed 'untarnished' as it were to Net Render. Yes, it involves a bunch of memory but ensures consistency (especially if the values are being calculated per frame). This is what I had to do for the randomization algorithms in Greebler so that it would work with Net Render.
On 22/06/2012 at 07:01, xxxxxxxx wrote:
I think this is what I'm going to have to do. I added a second PC to the network this morning, and the two PCs generate identical series of random numbers but the Mac is different. Not too surprising I guess, given the different hardware and OS, but a pain all the same.
Guess I'll have to add a routine to generate a whole series of randoms in advance and have the plugin access that rather than use Random() as and when required.
Thanks very much for the response, it's always good to see that there is a solution to a problem!
On 27/06/2012 at 04:26, xxxxxxxx wrote:
just write your own random number generator. the old c4d one is pants.
there is a new class in the SDK called Stratified2DRandom.
That might well be better choice. However, its best not to rely on c4d classes for things like this.I would consider that class way past its sellby date and would not be suprised to see it go soon.
Write your own classes for things like this and you have control over it now and in the future.
On 27/06/2012 at 04:49, xxxxxxxx wrote:
Thanks Paul. I did try to use a set of ready-generated randoms but I've got a lot of random number usage and it got to be a nightmare keeping track of indices into arrays. I'll do as you suggest, seems the best way to go for my purposes.
On 27/06/2012 at 06:14, xxxxxxxx wrote:
When it comes to any library it is best that it is ubiquitous across computer systems. I'm really surprised that the C4D random number class differs on PC and Mac. It shouldn't if it was designed to return similar results always (esp. considering that both PCs and Macs now use Intel chips!). My sus**cion would be that Maxon is using random number generators built into the OS and these differ (for shame!). As Paul said, it is easy enough to get well-built random number generator code and integrate it as a class or set of classes into your code. I did the same thing when limitations in the C4D collision support was wanting.
On 27/06/2012 at 07:23, xxxxxxxx wrote:
Without seeing the code one cannot tell what the problem is. Where did you initialise and seed it exactly? What is the threading context?
On 27/06/2012 at 08:11, xxxxxxxx wrote:
@Robert: The odd thing is, looking at the numbers generated the first four are identical on both PC and Mac. After that they are completely different, it's not even as if the same series of numbers appears at different times. I would think it was a case of using hardware RNGs but then why are the first four numbers always the same? Like you, I would have thought that the RNG in the SDK would always give the same series from the same seed irrespective of hardware.
@Samir: the Random() class is initialised in the Init() function of the ObjectData plugin, then it's re-initialised with the same seed every time the timeline is reset to the starting frame.
Right now, I'm going to try a third-party library and see what happens. I'll report back.