# Generating Random Numbers in Ruby: rand, Random & SecureRandom

DevFeed: [Generating Random Numbers in Ruby: rand, Random & SecureRandom](<https://devfeed.tech/articles/generating-random-numbers-in-ruby-rand-random-securerandom-85899.md>)

Original publisher: [Read original article](<https://blog.appsignal.com/2018/07/31/generating-random-numbers-in-ruby.html>)

Author: Joyce Echessa

Published: 2018-07-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [AppSignal](<https://devfeed.tech/sources/appsignal.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [Randomizer](<https://devfeed.tech/topics/randomizer.md>), [RSpec](<https://devfeed.tech/topics/rspec.md>)

Tags: [algorithm](<https://devfeed.tech/tags/algorithm.md>), [api-keys](<https://devfeed.tech/tags/api-keys.md>), [database](<https://devfeed.tech/tags/database.md>), [entropy](<https://devfeed.tech/tags/entropy.md>), [passwords](<https://devfeed.tech/tags/passwords.md>), [random](<https://devfeed.tech/tags/random.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [tests](<https://devfeed.tech/tags/tests.md>), [tokens](<https://devfeed.tech/tags/tokens.md>)

## AI overview

A practical guide to Ruby randomness explains when to use `rand`, seeded `Random` instances, and `SecureRandom`. It covers ranges, reproducible tests, secure tokens and UUIDs, and when third-party gems can help with statistical distributions or realistic fake data.

## Source excerpt

Learn every way to generate random numbers in Ruby: rand and ranges, seeded Random instances for tests, and SecureRandom for tokens, UUIDs, and passwords.