[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: [ANN] new random_data gem for better development data

Victor 'Zverok' Shepelev

9/21/2007 11:00:00 AM

From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf Of
Mike Subelsky
Sent: Friday, September 21, 2007 1:52 AM
>
>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 Doe"
>
>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.ruby...
>

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.


1 Answer

Mike Subelsky

9/23/2007 6:15:00 PM

0

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.ruby......

-Mike

Victor "Zverok" Shepelev wrote:
> From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf
> Of
> Mike Subelsky
> Sent: Friday, September 21, 2007 1:52 AM
>>
>>http://random-data.ruby...
>>
>
> 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.

--
Posted via http://www.ruby-....