Skip to main content
Added example using numbers
Source Link
Bob Hanlon
  • 167.4k
  • 7
  • 83
  • 213
$Version (* "14.3.0 for Mac OS X ARM (64-bit) (July 8, 2025)" *) Clear["Global`*"] colors = { {yellow, 1, {255, 221, 51}}, {blue, 2, {0, 102, 204}}, {red, 3, {204, 0, 0}}, {purple, 4, {102, 0, 153}}, {orange, 5, {255, 102, 0}}, {green, 6, {0, 153, 0}}, {maroon, 7, {153, 51, 51}}, {black, 8, {0, 0, 0}}}; (#1 := Graphics[{RGBColor[#3/255], Disk[{0, 0}, 1/8], White, Disk[{0, 0}, 1/28], Black, Text[Style[#2, 24]]}]) & @@@ colors; Grid[RandomChoice[colors[[All, 1]], {6, 4}], ItemSize -> 6] 

enter image description here

Grid[{{red, yellow, blue}, {maroon, black, yellow}}, ItemSize -> 6] 

enter image description here

EDIT: Using numbers

Grid[mat = RandomChoice[Range[8], {2, 4}]] 

enter image description here

Grid[Map[colors[[#, 1]] &, mat, {2}], ItemSize -> 6] 

enter image description here

$Version (* "14.3.0 for Mac OS X ARM (64-bit) (July 8, 2025)" *) Clear["Global`*"] colors = { {yellow, 1, {255, 221, 51}}, {blue, 2, {0, 102, 204}}, {red, 3, {204, 0, 0}}, {purple, 4, {102, 0, 153}}, {orange, 5, {255, 102, 0}}, {green, 6, {0, 153, 0}}, {maroon, 7, {153, 51, 51}}, {black, 8, {0, 0, 0}}}; (#1 := Graphics[{RGBColor[#3/255], Disk[{0, 0}, 1/8], White, Disk[{0, 0}, 1/28], Black, Text[Style[#2, 24]]}]) & @@@ colors; Grid[RandomChoice[colors[[All, 1]], {6, 4}], ItemSize -> 6] 

enter image description here

Grid[{{red, yellow, blue}, {maroon, black, yellow}}, ItemSize -> 6] 

enter image description here

$Version (* "14.3.0 for Mac OS X ARM (64-bit) (July 8, 2025)" *) Clear["Global`*"] colors = { {yellow, 1, {255, 221, 51}}, {blue, 2, {0, 102, 204}}, {red, 3, {204, 0, 0}}, {purple, 4, {102, 0, 153}}, {orange, 5, {255, 102, 0}}, {green, 6, {0, 153, 0}}, {maroon, 7, {153, 51, 51}}, {black, 8, {0, 0, 0}}}; (#1 := Graphics[{RGBColor[#3/255], Disk[{0, 0}, 1/8], White, Disk[{0, 0}, 1/28], Black, Text[Style[#2, 24]]}]) & @@@ colors; Grid[RandomChoice[colors[[All, 1]], {6, 4}], ItemSize -> 6] 

enter image description here

Grid[{{red, yellow, blue}, {maroon, black, yellow}}, ItemSize -> 6] 

enter image description here

EDIT: Using numbers

Grid[mat = RandomChoice[Range[8], {2, 4}]] 

enter image description here

Grid[Map[colors[[#, 1]] &, mat, {2}], ItemSize -> 6] 

enter image description here

added second example
Source Link
Bob Hanlon
  • 167.4k
  • 7
  • 83
  • 213
$Version (* "14.3.0 for Mac OS X ARM (64-bit) (July 8, 2025)" *) Clear["Global`*"] colors = { {yellow, 1, {255, 221, 51}}, {blue, 2, {0, 102, 204}}, {red, 3, {204, 0, 0}}, {purple, 4, {102, 0, 153}}, {orange, 5, {255, 102, 0}}, {green, 6, {0, 153, 0}}, {maroon, 7, {153, 51, 51}}, {black, 8, {0, 0, 0}}}; (#1 := Graphics[{RGBColor[#3/255], Disk[{0, 0}, 1/8], White, Disk[{0, 0}, 1/28], Black, Text[Style[#2, 24]]}]) & @@@ colors; Grid[RandomChoice[colors[[All, 1]], {6, 4}], ItemSize -> 6] 

enter image description here

Grid[{{red, yellow, blue}, {maroon, black, yellow}}, ItemSize -> 6] 

enter image description here

$Version (* "14.3.0 for Mac OS X ARM (64-bit) (July 8, 2025)" *) Clear["Global`*"] colors = { {yellow, 1, {255, 221, 51}}, {blue, 2, {0, 102, 204}}, {red, 3, {204, 0, 0}}, {purple, 4, {102, 0, 153}}, {orange, 5, {255, 102, 0}}, {green, 6, {0, 153, 0}}, {maroon, 7, {153, 51, 51}}, {black, 8, {0, 0, 0}}}; (#1 := Graphics[{RGBColor[#3/255], Disk[{0, 0}, 1/8], White, Disk[{0, 0}, 1/28], Black, Text[Style[#2, 24]]}]) & @@@ colors; Grid[RandomChoice[colors[[All, 1]], {6, 4}], ItemSize -> 6] 

enter image description here

$Version (* "14.3.0 for Mac OS X ARM (64-bit) (July 8, 2025)" *) Clear["Global`*"] colors = { {yellow, 1, {255, 221, 51}}, {blue, 2, {0, 102, 204}}, {red, 3, {204, 0, 0}}, {purple, 4, {102, 0, 153}}, {orange, 5, {255, 102, 0}}, {green, 6, {0, 153, 0}}, {maroon, 7, {153, 51, 51}}, {black, 8, {0, 0, 0}}}; (#1 := Graphics[{RGBColor[#3/255], Disk[{0, 0}, 1/8], White, Disk[{0, 0}, 1/28], Black, Text[Style[#2, 24]]}]) & @@@ colors; Grid[RandomChoice[colors[[All, 1]], {6, 4}], ItemSize -> 6] 

enter image description here

Grid[{{red, yellow, blue}, {maroon, black, yellow}}, ItemSize -> 6] 

enter image description here

Source Link
Bob Hanlon
  • 167.4k
  • 7
  • 83
  • 213

$Version (* "14.3.0 for Mac OS X ARM (64-bit) (July 8, 2025)" *) Clear["Global`*"] colors = { {yellow, 1, {255, 221, 51}}, {blue, 2, {0, 102, 204}}, {red, 3, {204, 0, 0}}, {purple, 4, {102, 0, 153}}, {orange, 5, {255, 102, 0}}, {green, 6, {0, 153, 0}}, {maroon, 7, {153, 51, 51}}, {black, 8, {0, 0, 0}}}; (#1 := Graphics[{RGBColor[#3/255], Disk[{0, 0}, 1/8], White, Disk[{0, 0}, 1/28], Black, Text[Style[#2, 24]]}]) & @@@ colors; Grid[RandomChoice[colors[[All, 1]], {6, 4}], ItemSize -> 6] 

enter image description here