How can one generate a (digital) key about 6 digits, it is necessary that each user has his own key, and so that it does not repeat. I looked at the uuid but there I generated a complex key, and I did not find how to change the generation. but you can use the random method, if it is, then there must be some kind of validation, and as I understood the custom one. So, I did not write custom validations, I would like to help or at least redirect to the correct sources

  • 6 numbers exactly? Not enough? These are 1 000 000 accounts (and one person can start several), then the keys will inevitably be repeated. Or do you need a key for a short time? - cheops
  • one
    There is such a concept "XY-problem", when the question is not about the problem, but about an unsuccessful attempt to solve it. Tell us why you need it, most likely, there is a more adequate solution. - D-side
  • @Andrey-Shostyk for this is usually used slug, try friendly_id gem - Mal Skrylev
  • @cheops> These are 1,000,000 accounts . Not quite, if he means slug, then it is usually not 10 ^ 6, but 26 ^ 6 or even 36 ^ 6 (~ 2 billion) =) - Mal Skrylev

0