# \[ANN\] new random\_data gem for better development data

**URL:** <https://www.ruby-forum.com/t/ann-new-random-data-gem-for-better-development-data/115146>\
**Category:** Ruby\
**Created:** [September 21, 2007, 12:51am UTC](https://www.ruby-forum.com/t/ann-new-random-data-gem-for-better-development-data/115146 "2007-09-21T00:51:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [September 21, 2007, 12:51am UTC](https://www.ruby-forum.com/t/ann-new-random-data-gem-for-better-development-data/115146/1 "2007-09-21T00:51:51Z")

</div>

I’ve released a small gem that provides a Random singleton class with a  
series of methods for generating random test data including names,  
mailing addresses, dates, phone numbers, e-mail addresses, and text.  
This lets you quickly mock up realistic looking data for informal  
testing.

Instead of:

> > foo.name = “John D.”

You get:

> > foo.name = “#{Random.firstname} #{Random.initial} #{Random.lastname}”  
> > foo.name  
> > =\> “Miriam R. Xichuan”

The gem also includes code for phone numbers, e-mail addresses, physical  
addresses, and (primitive) text generation.

For more details and full documentation, visit:  
[http://random-data.rubyforge.org/](http://random-data.rubyforge.org/)

-Mike

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [September 21, 2007, 1:00pm UTC](https://www.ruby-forum.com/t/ann-new-random-data-gem-for-better-development-data/115146/2 "2007-09-21T13:00:31Z")

</div>

From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf  
Of  
Mike Subelsky  
Sent: Friday, September 21, 2007 1:52 AM

> [http://random-data.rubyforge.org/](http://random-data.rubyforge.org/)

Wow! Really, really cool.

Two suggestions.

1. I’d like to have it localized (to generate random Russian/Ukrainian  
names  
and realistic-looking addresses). I can do it myself, but it’ll require  
you  
to change internals to allow localizations?

2. Literally yesterday I’ve also done something for “realistic looking”  
data, but in numbers and probabilities area (example with students):

if probable(0.7) # with 70% probability

# student have done nearly 20 right answers

student.answer\_count = (~20.0).to\_i  
else # with 30% probability

# he have done nearly 10 right answers

student.answer\_count = (~10.0).to\_i  
end

Here are two “tricky functions”:

# probable(pct) returns true with pct probability (or calls block

provided)

def probable(pct)  
happened = rand \< pct  
yield if happened && block\_given?  
return happened  
end

# Number#~ read is “nearly” and returns something like number ± 15%:

class Numeric  
LEVEL = 0.3  
def ~  
self + self \* rand(LEVEL) \* LEVEL - self\* LEVEL/2.0  
end  
end

I think, as my “magic” tend to be used in same circumstances as yours,  
it  
can be joined into the same gem.

V.

---

<div class="post-metadata">

**Author:** ![mschwab](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/59ef9b/32.png) [@mschwab](https://www.ruby-forum.com/u/mschwab)\
**Post date:** [September 23, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/ann-new-random-data-gem-for-better-development-data/115146/3 "2007-09-23T20:14:47Z")

</div>

Victor,

Those are both great ideas. I’d love to incorporate both of them in the  
gem; feel free to send me any patches at mike…at…subelsky.com.

The SVN repository is here:  
svn checkout [http://random-data.rubyforge.org/svn/trunk/](http://random-data.rubyforge.org/svn/trunk/)

-Mike

Victor “Zverok” Shepelev wrote:

> From: removed\_email\_address@domain.invalid [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)] On Behalf  
> Of  
> Mike Subelsky  
> Sent: Friday, September 21, 2007 1:52 AM
> 
> > [http://random-data.rubyforge.org/](http://random-data.rubyforge.org/)
> 
> Wow! Really, really cool.
> 
> Two suggestions.
> 
> 1. I’d like to have it localized (to generate random Russian/Ukrainian  
> names  
> and realistic-looking addresses). I can do it myself, but it’ll require  
> you  
> to change internals to allow localizations?
> 
> 2. Literally yesterday I’ve also done something for “realistic looking”  
> data, but in numbers and probabilities area (example with students):
> 
> if probable(0.7) # with 70% probability
> 
> # student have done nearly 20 right answers
> 
> student.answer\_count = (~20.0).to\_i  
> else # with 30% probability
> 
> # he have done nearly 10 right answers
> 
> student.answer\_count = (~10.0).to\_i  
> end
> 
> Here are two “tricky functions”:
> 
> # probable(pct) returns true with pct probability (or calls block
> 
> provided)
> 
> def probable(pct)  
> happened = rand \< pct  
> yield if happened && block\_given?  
> return happened  
> end
> 
> # Number#~ read is “nearly” and returns something like number ± 15%:
> 
> class Numeric  
> LEVEL = 0.3  
> def ~  
> self + self \* rand(LEVEL) \* LEVEL - self\* LEVEL/2.0  
> end  
> end
> 
> I think, as my “magic” tend to be used in same circumstances as yours,  
> it  
> can be joined into the same gem.
> 
> V.
