# \[Feature Request\] adding .sample to ActiveRecord

**URL:** <https://discuss.rubyonrails.org/t/feature-request-adding-sample-to-activerecord/73040>\
**Category:** rubyonrails-core\
**Created:** [March 28, 2018, 4:59am UTC](https://discuss.rubyonrails.org/t/feature-request-adding-sample-to-activerecord/73040 "2018-03-28T04:59:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Regan\_Ryan](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Regan\_Ryan](https://discuss.rubyonrails.org/u/Regan_Ryan)\
**Post date:** [March 28, 2018, 4:59am UTC](https://discuss.rubyonrails.org/t/feature-request-adding-sample-to-activerecord/73040/1 "2018-03-28T04:59:51Z")

</div>

Hi there,

I’ve never contributed to Rails before, so if I’m doing something wrong, please point me in the right direction.

I often do something like `User.all.sample` in Rails console to get a random record. This is ok, but it loads every record from the db before calling `sample` to get a single record. Some projects have 100k+ users, so that takes some time.

**I would like to contribute to Rails by adding a `ActiveRecord::Scoping::Named::ClassMethods#sample` method to retrieve a single (or more if an argument is specified) random record from the db.**

I’ve been reading a couple of “how to contribute to rails” guides, one of them led me to this group. Is anyone able to guide me from here? How do I get approval for this feature?

Cheers,

Regan

---

<div class="post-metadata">

**Author:** ![rafaelfranca](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/rafaelfranca/32/616_2.png) [@rafaelfranca](https://discuss.rubyonrails.org/u/rafaelfranca)\
**Post date:** [March 28, 2018, 5:33am UTC](https://discuss.rubyonrails.org/t/feature-request-adding-sample-to-activerecord/73040/2 "2018-03-28T05:33:14Z")

</div>

One of the first things to do is check if this feature would not proposed before. I think you will see that it was already proposed and rejected.

See [https://github.com/rails/rails/pull/16997](https://github.com/rails/rails/pull/16997)
