Added random generator. API fix. Added tests.