# Whiteknight/Rosella

### Subversion checkout URL

You can clone with
or
.
Fetching contributors…

Cannot retrieve contributors at this time

79 lines (69 sloc) 2.05 KB
 \$include "Rosella/Core.winxed"; \$include "Rosella/Random.winxed"; // Mersenne Twister example. function mersenne_main() { var rnd = Rosella.Random.default_uniform_random(); print("\n20 random uniformly-distributed integers: "); for(int i = 0; i < 20; i++) { print(rnd.get_int()); print(" "); } say(""); print("\n20 random uniformly-distributed floats: "); for(int i = 0; i < 20; i++) { print(rnd.get_float()); print(" "); } say(""); print("\n20 random uniformly-distributed ints in [0, 10): "); for(int i = 0; i < 20; i++) { print(rnd.get_range(0, 10)); print(" "); } say(""); say("\nHistogram of 500 uniformly-distributed floats: "); int buckets_a[] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; for (int i = 0; i < 500; i++) { int idx = rnd.get_range(0, 21); if (idx >= 0 && idx < elements(buckets_a)) buckets_a[idx] = buckets_a[idx] + 1; } for (int i = 0; i < elements(buckets_a); i++) { print(i, ": "); for (int j = 0; j < int(buckets_a[i]); j++) print("#"); say(""); } rnd = Rosella.Random.default_normal_random(0.00, 0.25); print("\n20 random normal-distributed floats: "); for (int i = 0; i < 20; i++) { print(rnd.get_float()); print(" "); } say(""); rnd = Rosella.Random.default_normal_random(10.00, 3.00); say("\nHistogram of 500 normal-distributed floats: "); int buckets[] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; for (int i = 0; i < 500; i++) { float value = rnd.get_float() + 0.5; \${ floor value, value }; int idx = int(value); if (idx >= 0 && idx < elements(buckets)) buckets[idx] = buckets[idx] + 1; } for (int i = 0; i < elements(buckets); i++) { print(i, ": "); for (int j = 0; j < int(buckets[i]); j++) print("#"); say(""); } } function main[main]() { using mersenne_main; Rosella.Parrot.try_report(mersenne_main); }
Something went wrong with that request. Please try again.