# Marlborough Hour of Code 2020

## Random Function and the For Loop (Katie ‘23)

Apologies for the weird audio in this video! Here’s the tutorial!

This is what the completed code will look like. Tip: it’ll be different every time you press play/reload the page!

``````function setup() {
var x;
var y;
var w;
var r;
var g;
var b;
var a;
var c;

background(255);
createCanvas(400, 400);
noStroke();

for (var i = 0; i < 20; i++) {
x = random(width);
y = random(width);
w = random(10, 100);
r = random(255);
g = random(255);
b = random(255);
a = random(100, 200);
c = random(5, 10);
fill(r, g, b, a);
rect(x, y, w, w, c);

}

}

function draw() {
r = random(255);
g = random(255);
b = random(255);
c = random(5, 10);
a = random(100, 200);
fill(r, g, b, a);
rect(0, 0, 10, height);
rect(0, 0, width, 10);
rect(width - 10, 0, 10, height);
rect(0, height - 10, width, 10);
}

``````

You can put code here and try it out!

Copy the code into the editor below to run it yourself!
{"ft_lang_label":"__label__en","ft_lang_prob":0.5494142,"math_prob":0.99931157,"size":915,"snap":"2021-43-2021-49","text_gpt3_token_len":313,"char_repetition_ratio":0.19868277,"word_repetition_ratio":0.058479533,"special_character_ratio":0.43497267,"punctuation_ratio":0.27755103,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9926567,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-19T23:38:00Z\",\"WARC-Record-ID\":\"<urn:uuid:f1aa3cab-251c-4b50-a663-d629f8d5f510>\",\"Content-Length\":\"11217\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:cebcfb85-8f1e-4c58-b72f-03ce415a920e>\",\"WARC-Concurrent-To\":\"<urn:uuid:a3c2afab-b310-442a-8a17-15933545c3ea>\",\"WARC-IP-Address\":\"185.199.109.153\",\"WARC-Target-URI\":\"https://dkessner.github.io/MarlboroughHourOfCode2020/randomLoops.html\",\"WARC-Payload-Digest\":\"sha1:AXU67P6WLRM5V7SHFNLGKZQSES2XWJGG\",\"WARC-Block-Digest\":\"sha1:W3HK2FDQ4Y7XQULBY77YNEKFMEY3CF3O\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323585290.83_warc_CC-MAIN-20211019233130-20211020023130-00569.warc.gz\"}"}