Oheinen ohjelma montecarlo3.c laskee piin arvoa Monte Carlo -menetelmällä halutulla määrällä rinnakkaisia prosesseja. Argumentteina annetaan haluttu kokonaispistemäärä, kullakin lapsiprosessilla kerralla laskettava pistemäärä sekä siemenluku kunkin lapsiprosessin satunnaislukugenerattorille. Siinä on bugi: käynnistettäessä samannumeroinen lapsiprosessi uudestaan sen satunnaislukugeneraattorikin alustetaan uudestaan samalla siemenluvulla, joten tuloskin on aina sama. Korjaa se niin, että satunnaislukugeneraattorin tila säilytetään samannumeroisen lapsiprosessin seuraavaan käynnistykseen. (Vihje: man random) Esimerkkiajo - huomaa miten samannumeroinen lapsi saa aina samat tulokset: $ ./montecarlo3 100000 11000 1 2 3 starting child 0 with seed 1 and 11000 rounds starting child 1 with seed 2 and 11000 rounds starting child 2 with seed 3 and 11000 rounds child 0 reported 8699:11000 -> 3.163273 child 1 reported 8670:11000 -> 3.152727 child 2 reported 8676:11000 -> 3.154909 starting child 0 with seed 1 and 11000 rounds starting child 1 with seed 2 and 11000 rounds starting child 2 with seed 3 and 11000 rounds child 0 reported 8699:11000 -> 3.163273 child 1 reported 8670:11000 -> 3.152727 child 2 reported 8676:11000 -> 3.154909 starting child 0 with seed 1 and 11000 rounds starting child 1 with seed 2 and 11000 rounds starting child 2 with seed 3 and 11000 rounds child 0 reported 8699:11000 -> 3.163273 child 1 reported 8670:11000 -> 3.152727 child 2 reported 8676:11000 -> 3.154909 starting child 0 with seed 1 and 1000 rounds child 0 reported 783:1000 -> 3.132000 Total: 78918:100000 -> 3.156720 Vastaavasti korjatulla versiolla: $ ./montecarlo3 100000 11000 1 2 3 Initializing child 0 with seed 1 Initializing child 1 with seed 2 Initializing child 2 with seed 3 starting child 0 with 11000 rounds starting child 1 with 11000 rounds starting child 2 with 11000 rounds child 0 reported 8699:11000 -> 3.163273 child 1 reported 8670:11000 -> 3.152727 child 2 reported 8676:11000 -> 3.154909 starting child 0 with 11000 rounds starting child 1 with 11000 rounds starting child 2 with 11000 rounds child 0 reported 8726:11000 -> 3.173091 child 1 reported 8657:11000 -> 3.148000 child 2 reported 8708:11000 -> 3.166545 starting child 0 with 11000 rounds starting child 1 with 11000 rounds starting child 2 with 11000 rounds child 0 reported 8615:11000 -> 3.132727 child 1 reported 8605:11000 -> 3.129091 child 2 reported 8685:11000 -> 3.158182 starting child 0 with 1000 rounds child 0 reported 783:1000 -> 3.132000 Total: 78824:100000 -> 3.152960