6

Each time I execute the following code it generates the same cylinders with the same format.

SeedRandom[157]
cylinders = 
  Table[{RandomReal[{-100, 100}, {2, 3}], RandomReal[5]}, {50}];
SeedRandom[157]
ImageCrop[
 Graphics3D[{EdgeForm[None], 
     Directive[Opacity@RandomReal[{.4, .9}], Hue[RandomReal[]]], 
     Cylinder[First@#, Last@#]} & /@ cylinders, Boxed -> False, 
  ImageSize -> 800]]

enter image description here However,

SeedRandom[157]
cylinders = 
  ParallelTable[{RandomReal[{-100, 100}, {2, 3}], 
    RandomReal[5]}, {50}];
SeedRandom[157]
ImageCrop[
 Graphics3D[{EdgeForm[None], 
     Directive[Opacity@RandomReal[{.4, .9}], Hue[RandomReal[]]], 
     Cylinder[First@#, Last@#]} & /@ cylinders, Boxed -> False, 
  ImageSize -> 800]]

enter image description here

does not exhibit the same behavior. I guess I am missing something fundamental here.

Dimitris
  • 4,794
  • 22
  • 50

1 Answers1

6
ParallelEvaluate[SeedRandom[157]]
cylinders = 
  ParallelTable[{RandomReal[{-100, 100}, {2, 3}], 
    RandomReal[5]}, {50}];
SeedRandom[157]
ImageCrop[
 Graphics3D[{EdgeForm[None], 
     Directive[Opacity@RandomReal[{.4, .9}], Hue[RandomReal[]]], 
     Cylinder[First@#, Last@#]} & /@ cylinders, Boxed -> False, 
  ImageSize -> 800]]

enter image description here

ParallelEvaluate[SeedRandom[157 + $KernelID]]
cylinders = 
  ParallelTable[{RandomReal[{-100, 100}, {2, 3}], 
    RandomReal[5]}, {50}];
SeedRandom[157]
ImageCrop[
 Graphics3D[{EdgeForm[None], 
     Directive[Opacity@RandomReal[{.4, .9}], Hue[RandomReal[]]], 
     Cylinder[First@#, Last@#]} & /@ cylinders, Boxed -> False, 
  ImageSize -> 800]]

enter image description here

Karsten7
  • 27,448
  • 5
  • 73
  • 134