Random assignment of a column value

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.

Thank you in advance!!!

Hi,

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

here - how to use buttons

write your script

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.

1 Like

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?

1 Like

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.

NewGoogleSite

Then I will have to solve the problem of how can I keep the New Google Sites updated in real time when the tables on Airtable changes without clicking on refresh button. (Any ideas?)

Thank you in advance!!!