All of the code you need to reproduce it is in this gist. You will need to create both the weighted_dot_density.sql and select_random_weights.sql functions in your Carto account (just copy and past them in to the SQL terminal)
Then you run the query once for each ethnicity which gives you 4 tables with dot density in each for each ethnicity. Oh and after you run the create table queries you need to run
select cdb_cartodbfytable('account_name', 'table_name')
to have it show up in your datasts
You can then ether union them together to make one table or just create 4 layers on the map. You will want to do this through the batch API, I can help you write some scripts to do that if you like. Also the batch API docs are here: