# Using Random::ISAAC to generate random ids

**URL:** <https://forum.crystal-lang.org/t/using-random-isaac-to-generate-random-ids/969>\
**Category:** Help & Support\
**Created:** [July 19, 2019, 4:56pm UTC](https://forum.crystal-lang.org/t/using-random-isaac-to-generate-random-ids/969 "2019-07-19T16:56:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)\
**Post date:** [July 19, 2019, 4:56pm UTC](https://forum.crystal-lang.org/t/using-random-isaac-to-generate-random-ids/969/1 "2019-07-19T16:56:28Z")

</div>

I want to generate some random id values. I know there are many ways one can do this. But I want to understand why the code below is not working. It gives the same id _most_ of the times; about 1/10 is different, but 9/10 it is the same. Where is the error, and how can I fix it? Thank you for the help.

```
require "random/isaac"

def rnd_alpha_numeric_id()
    srcstr = "abcdefghjkmnpqrstuvwxyz" ## all except i, l and o
    rndinst = Random::ISAAC.new
    rndstr = srcstr.chars
                   .sample(6, rndinst)
                   .join
                
    rndnum = rndinst.rand(100000..999999)
    return "#{rndstr}-#{rndnum}"
end
            
10.times do |i|
    puts "#{i}: #{rnd_alpha_numeric_id()}"
end

```

Link to Crystal playground: [https://play.crystal-lang.org/#/r/7980](https://play.crystal-lang.org/#/r/7980)

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [July 19, 2019, 6:02pm UTC](https://forum.crystal-lang.org/t/using-random-isaac-to-generate-random-ids/969/2 "2019-07-19T18:02:08Z")

</div>

Yes, it’s a bug. Could you report it? Thank you!

---

<div class="post-metadata">

**Author:** ![curious2learn](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@curious2learn](https://forum.crystal-lang.org/u/curious2learn)\
**Post date:** [July 19, 2019, 6:22pm UTC](https://forum.crystal-lang.org/t/using-random-isaac-to-generate-random-ids/969/3 "2019-07-19T18:22:03Z")

</div>

Thank you @asterite. I have created the issue at [https://github.com/crystal-lang/crystal/issues/7976](https://github.com/crystal-lang/crystal/issues/7976)

(Edit reason: Added link to the created issue).
