# Generating random odd integer

**URL:** <https://www.ruby-forum.com/t/generating-random-odd-integer/171800>\
**Category:** Rails\
**Created:** [July 9, 2009, 1:20pm UTC](https://www.ruby-forum.com/t/generating-random-odd-integer/171800 "2009-07-09T13:20:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miss\_moviestar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@miss\_moviestar](https://www.ruby-forum.com/u/miss_moviestar)\
**Post date:** [July 9, 2009, 1:20pm UTC](https://www.ruby-forum.com/t/generating-random-odd-integer/171800/1 "2009-07-09T13:20:59Z")

</div>

hi  
how can i generate random odd integers?  
i want it to refer to user.id  
thanks

---

<div class="post-metadata">

**Author:** ![miss\_moviestar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ecae2f/32.png) [@miss\_moviestar](https://www.ruby-forum.com/u/miss_moviestar)\
**Post date:** [July 9, 2009, 1:33pm UTC](https://www.ruby-forum.com/t/generating-random-odd-integer/171800/2 "2009-07-09T13:33:09Z")

</div>

Am 09.07.2009 um 13:20 schrieb Ghazal M.:

> how can i generate random odd integers?

Something like: 2 \* rand(6) + 1 ? The example will give you an odd  
number between 1 and 11 (both included). Adapt the number in rand as  
needed.

More details here [module Kernel - RDoc Documentation](http://ruby-doc.org/core/classes/Kernel.html#M005974)

As a side note: Google is your friend.

Felix
