Generate a string of digits of variable length

Is it possible to use strings of digits of variable length?

For example,

\d{9}

will generate a string of 9 random digits.

What I’d like to achieve is to have the length determined by a field in my schema. Something like:

\d{{{my_field}}}

This approach doesn’t work.

What would be an alternative?

I achieved what I wanted through a workaround.

I’ve stored the \d{9} in num_digits field, then on that field I did my_field.first(num_digits).

Still looking forward to learn from anyone if there are ways of achieving the same.

Remember that you can include pretty much any ruby code that you want and run using the “Formula” column type. To achieve what you are asking assuming the name of the other field was “Company Name” and you want to generate a string of numbers 0-9 based on the length of Company Name, I would add a Formula column and use:

(0...field('Company Name').length).map { random(0,9) }.join