Vous êtes sur la page 1sur 2

Daniel Farina Dfarina Lab Section N PS9 PART I 1. a. xi+1=(axi+c)%m if m=16: a must be 5, 9, or 13.

This fulfills the criteria that a-1 is divisible by 4 (5-1=4, 9-1=8, 13-1=12) c can be any odd number because the only common factor between any odd number from 1 to 15 and 16 would be 1. a=5, c=1 a=5, c=3 a=5, c=5 a=5, c=7 a=5, c=9 a=5, c=11 a=5, c=13 a=5, c=15 a=9, c=1 a=9, c=3 a=9, c=5 a=9, c=7 a=9, c=9 a=9, c=11 a=9, c=13 a=9, c=15 a=13, c=1 a=13, c=3 a=13, c=5 a=13, c=7 a=13, c=9 a=13, c=11 a=13, c=13 a=13, c=15 b. All the sequences are different. a=5, c=1, m=16 returns: 1 6 11 0 5 10 15 4 9 14 3 8 13 2 7 12 1 a=5, c=3, m=16 returns: 3 8 13 2 7 12 1 6 11 0 5 10 15 4 9 14 3 a=9, c=1, m=16 returns: 1 10 3 12 5 14 7 0 9 2 11 4 13 6 15 8 1

Due to the LCG formula, the pseudorandom list is generated based on a pattern, but different a and c values will create different sequences. c. All sequences contain the numbers 1-15 because m=16 and it is therefore a period of 16. 2. In the line:
if pick() % 13 != 0 : total = total + pick() % 13

It lists pick() twice. The first time will test to see if pick() comes up with an ace(0,13,26,39), but the second time it will run pick() again and add a value that is randomly generated and may not be the same as the first one. In order avoid this, they would need to assign a value to pick() so that it would use the same generated number. 3. They are not equivalent. In Arvinds function, he calls the function twice, with each call having a 50% chance of heads (0) and a 50% chance of tails (1). Bharats function is called only once with a 33% chance of 0, 1, or 2. While one could argue that a 2 would imply that tails was flipped twice in a row, this is not accurate. Assuming heads and tails have an equal 50% chance of being the result, like in Arvinds function, flipping tails twice would come out to be .5*.5=.25, or 25% chance probability. Bharats is inaccurate because it assumes that there is a 33% chance probability for this occurrence. Part II 1. - If you are a city planner and you want to simulate the durability of buildings before investing in large-scale construction and production. - In order to test a scientific hypothesis by simulating real world scenarios - In order to model how quickly a virus can spread and its pattern 2. a. Changing the for loop range to 50 instead of 40 causes the body to travel farther and closer to the center. b. Changing the for loop range to 70 from 50 causes it to loop all the way around the middle and come out close to where it started. This can be explained due to its behavior of falling toward the other bodies and the fact that once it is near the center, its gravitational force is much higher. Therefore, it shoots toward the center, but not in a direct path, and goes far past it. 3. a. The sun as well as the four closest planets (Mercury, Venus, Earth, Mars) are visible. Approximately 30 days or 1 month are taking place during the simulation. b. 15^2=225 force calculations each step c. O(n^2) force calculations

Vous aimerez peut-être aussi