This command is very slow if you use G’MIC CLI.
The number of colors with the original script is limited to 12, you can adapt it according to your wishes, it is free software.
Here are 2 examples including one with 4 random colors.
gmic -v - -m sylvie_alexandre.gmic 1024,1024,1,3 -samj_Palette_De_Degrades 159,190,195,55,67,140,54,40,39,140,81,88,207,175,190,220,202,196,170,186,192,130,149,139,112,96,96,237,168,138,220,199,205,234,217,219,0,0,512,20 -rm[-1] -o degrade.png
gmic -v - -m sylvie_alexandre.gmic 1024,1024,1,3 -samj_Palette_De_Degrades {(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,{(u)*255}
,207,175,190,220,202,196,170,186,192,130,149,139,112,96,96,237,168,138,220,199,205,234,217,219,0,0,512,20 -rm[-1] -o degrade_4couleurs_aleatoires.png
source : https://github.com/dtschump/gmic-community/raw/master/include/sylvie_alexandre.gmic