Re: Random assignment of a column value

967 0
cancel
Showing results for
Did you mean:
5 - Automation Enthusiast

Hi there,
I need some help, I’m new on Airtable!

I’m trying to solve a college test.

I have created tables with forms, when filling out the forms and updating the tables I would like to have a button that randomly assigns me roles.

FORM 1

TABLE 1

FORM 2

TABLE 2

I created an automation to give a value Resistance to the Role column.

I have to write a script that randomly assigns a role for each record, the role can be Resistance or Spy.

The total number of roles depends on the total number of players. The total number of players is found in another table.

If the total number of players is 5 then 3 records must have a Resistance role and the other 2 Spy.
If the total number of players is 6 then 4 records must have a Resistance role and the other 2 Spy.
If the total number of players is 7 then 4 records must have a Resistance role and the other 3 Spy.
If the total number of players is 8 then 5 records must have a Resistance role and the other 3 Spy.
If the total number of players is 9 then 6 records must have a Resistance role and the other 3 Spy.
If the total number of players is 10 then 6 records must have a Resistance role and the other 4 Spy.

3 Replies 3
12 - Earth

Hi,

check tutorial example how to perform simple read/write operation on a table

here - how to use buttons

hint: I would create array
Roles=[‘Spy’, ‘Spy’, ‘Res’, ‘Res’, ‘Res’, ‘Res’, ‘Spy’, ‘Res’, ‘Res’, ‘Spy’]
then randomly sort your query result and assign these values to it, from first, no matter how much is total.

18 - Pluto

Can you please clarify if writing the script is part taking the test? If this is a test, how much outside help are you allowed to use?

5 - Automation Enthusiast

Thank you both for having answered !!

In reality it is not really a test, it is something to do and to give to a teacher.
I just have to be able to solve it.

I will be using the tables as frames in a New Google Site where players will go to play the game. Then the game manager will have to click on the “Choose Roles” button when all players are registered in the tables.