nondeterminism

Get Version

0.2.1

→ ‘nondeterminism’

What probabilistic code utilities

Installing

sudo gem install nondeterminism

The basics

Demonstration of usage

	# accept only half of emails
	50.percent_of_the_time do
		email.accept!
	end
	# accept only half of emails and send nasty
	# responses to the rest
	50.percent_of_the_time do
		email.accept!
	end.else do
		email.send_nasty_response!
	end
	# name should be
	# 	'jerome'  30% of the time
	# 	'kevin'   40% of the time
	# 	'leslie'  the rest of the time
	with_probability(0.30) do
		name = 'jerome'
	end.else_with_probability(0.40) do
		name = 'kevin'
	end.else
		name = 'leslie'
	end
	# select a random friend from an Array:
	friend = person.friends.random_element
	# call foo between 5 and 8 times (inclusive):
	(5..8).times do
		foo
	end

Customization

Using a custom random probability generator:

if you want to change the random-probability-generation mechanism, do something like:

	Nondeterminism::probability_generator = Proc.new { ... }

or

	Nondeterminism::probability_generator = my_obj

just make sure my_obj responds to #to_proc and the Proc only returns numbers in [0.0, 1.0]

Using a custom random integer generator:

if you want to change the random-integer-generation mechanism, do something like:

	Nondeterminism::integer_generator = Proc.new { |low, high| ... }

or

	Nondeterminism::integer_generator = Proc.new { |low, high| ... }

just make sure my_obj responds to #to_proc, the Proc has #arity = 2 (or < -2), and only returns numbers in [low, high]

Forum

http://groups.google.com/group/ruby-nondeterminism

How to submit patches

Read the 8 steps for fixing other people’s code and for section 8b: Submit patch to Google Groups, use the Google Group above.

The trunk repository is svn://rubyforge.org/var/svn/nondeterminism/trunk for anonymous access.

License

This code is free to use under the terms of the Apache License.

Contact

Comments are welcome. Send an email to Ruby Nondeterminism Google Group email via the forum

James Rosen, 30th January 2008
Theme extended from Paul Battley