# Is this a good way to generate a random string?

**URL:** <https://forum.crystal-lang.org/t/is-this-a-good-way-to-generate-a-random-string/6986>\
**Category:** Help & Support\
**Created:** [July 3, 2024, 5:51am UTC](https://forum.crystal-lang.org/t/is-this-a-good-way-to-generate-a-random-string/6986 "2024-07-03T05:51:19Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![ralsina](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ralsina/32/2139_2.png) [@ralsina](https://forum.crystal-lang.org/u/ralsina)\
**Post date:** [July 11, 2024, 11:28am UTC](https://forum.crystal-lang.org/t/is-this-a-good-way-to-generate-a-random-string/6986/21 "2024-07-11T11:28:41Z")

</div>

And I am now using that base58 shard, thanks :-)

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [December 5, 2024, 10:11pm UTC](https://forum.crystal-lang.org/t/is-this-a-good-way-to-generate-a-random-string/6986/22 "2024-12-05T22:11:23Z")

</div>

One thing I noticed is `to_slice.sample` yields a `UInt8` not an actual `Char` from the `chars` variable. So maybe need to change that line to like `io.write_byte chars.to_slice.sample`.

[Previous page](https://forum.crystal-lang.org/t/is-this-a-good-way-to-generate-a-random-string/6986.md?page=1)
