Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

デフォルトで srand で再現可能にする #52

Merged
merged 1 commit into from
Jul 2, 2023

Conversation

tmr111116
Copy link
Contributor

rspec を Kernel.srand config.seed の設定で使っているんですが、 Gimei の結果に再現性がない事に気づきました。
設定で変更できるようですが、デフォルトは srand で設定されるデフォルトの RNG を使うのがいいと思います。
Random クラスオブジェクトを使うのは Faker の faker-ruby/faker#2488 と同じです。

before:

irb(main):001:0> srand 42
=> 210865224690408955513486590071985786719
irb(main):002:0> Gimei.kanji
=> "長尾 憲剛"
irb(main):003:0> Gimei.kanji
=> "岡村 芽依"
irb(main):004:0> Gimei.kanji
=> "永井 恵子"
irb(main):005:0> srand 42
=> 42
irb(main):006:0> Gimei.kanji
=> "今野 由貴子"
irb(main):007:0> Gimei.kanji
=> "三上 菜夕"
irb(main):008:0> Gimei.kanji
=> "柳田 基之"
irb(main):009:0> 

after:

irb(main):001:0> srand 42
=> 16380877625997386394282233687557709970
irb(main):002:0> Gimei.kanji
=> "飯島 誠吾"
irb(main):003:0> Gimei.kanji
=> "篠原 卓朗"
irb(main):004:0> Gimei.kanji
=> "川口 響生"
irb(main):005:0> srand 42
=> 42
irb(main):006:0> Gimei.kanji
=> "飯島 誠吾"
irb(main):007:0> Gimei.kanji
=> "篠原 卓朗"
irb(main):008:0> Gimei.kanji
=> "川口 響生"

Copy link
Owner

@willnet willnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@willnet willnet merged commit ef94a0e into willnet:main Jul 2, 2023
@tmr111116 tmr111116 deleted the use-default-random branch July 3, 2023 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants