









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Today:
Coming Up: Concurrency and synchronization ( Data Structures, Chap- ter 10, and Programming Into Java, Chapter 9).
i = (i+1) % 55; X[i] += X[(i+31) % 55]; // Why +31 (55-24) instead of -24? return X[i]; /* modulo 232 */
/** Random integer in the range 0 .. n-1, n>0. */ int nextInt (int n) { long X = next random long ( 0 ≤ X < 248 ); if (n is 2 k for some k) return top k bits of X; int MAX = largest multiple of n that is < 248 ; while (Xi >= MAX) X = next random long ( 0 ≤ X < 248 ); return Xi / (MAX/n); }
1 y
x
Legend: 0: 1: 2: 3:
return (Ri % 1.0 > v[(int) Ri]) ? top[(int) Ri] : bot[Ri];
where v = { 1.0/3.0, 2.0/3.0, 0, 1.0/3.0 }; top = { 1, 2, 2, 1 }, bot = { 0, 1, /* ANY */ 0, 3 };
void shuffle (List L, Random R) for (int i = L.size (); i > 0; i -= 1) swap element i-1 of L with element R.nextInt (i) of L;
Swap items 0 1 2 3 4 5 Start A♣ 2 ♣ 3 ♣ A♥ 2 ♥ 3 ♥ 5 ⇐⇒ 1 A♣ 3 ♥ 3 ♣ A♥ 2 ♥ 2 ♣ 4 ⇐⇒ 2 A♣ 3 ♥ 2 ♥ A♥ 3 ♣ 2 ♣
Swap items 0 1 2 3 4 5 3 ⇐⇒ 3 A♣ 3 ♥ 2 ♥ A♥ 3 ♣ 2 ♣ 2 ⇐⇒ 0 2 ♥ 3 ♥ A♣A♥ 3 ♣ 2 ♣ 1 ⇐⇒ 0 3 ♥ 2 ♥ A♣A♥ 3 ♣ 2 ♣
/** Permute L and return sublist of K>=0 randomly