# Not able to set value of a thing thru' formula

Bubble beginner here; I am trying a very simple use-case - generating a whole random number between 1 and 7; I tried using the random number generator plugin, but it generates fractional number as well; I am now thinking of creating a random number through floor(rand() * 7) + 1 and creating it as part of the workflow. However, when i set the value to “Calculate Formula”, i just get few standard formula calculations. How do I go about it?

The above would do 0-9

For 1-7 you might need to create an option set, called numbers, then put in the values 1-7 as separate options in the set, then wherever you need the random number use a dynamic expression of get option number and the operator random item.

2 Likes

Thanks for the solution; I missed to mention that i was trying to generate random number as part of workflow and then use that number in subsequent steps. Can you please advise on this

Nice one! Extending it a bit … if Calc Ranndomstring :converted to number :modulo 7 + 1 was added, it would give the integers 1 to 7, but not a very uniform distribution, with 1-3 overrepresented by 10% each.

If you make length of characters 2, that gives 00 to 99, after modulo and +1 it gives 1 to 7, with 1-3 overrepresented by 1% each, which is a lot closer to uniform distribution.

The usual way for workflows: either store and retrieve, or pass in parameter to a custom event workflow. How to store and retrieve? Many methods: db, custom state, group value, plugins. Let’s see lots of people jump in with their favourite methods : )

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.