Ask your JavaScript questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

generate random pastel colors w/o Math.random() JavaScript

  • REFUNDED

I am using these scripts to generate bright pastel BGs.

I want a better random number generator than Math.random()

I would like generate a seed with http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html


<script>

set_class_color();

function set_class_color() {
skill_2400 = class_color();
skill_2200 = class_color();
skill_2000 = class_color();
skill_1800 = class_color();
skill_1600 = class_color();
skill_1400 = class_color();
skill_1200 = class_color();
skill_1000 = class_color();
skill_800 = class_color();
skill_600 = class_color();
skill_400 = class_color();
skill_200 = class_color();
skill_0 = class_color();
}

// lightness to be adjusted as needed (third value).

// THIS CODE NEEDS A REPLACEMENT WITH seedrandom.js
function class_color(){return "hsla(" + ~~(360 * Math.random()) + "," + "70%,"+"87.5%,1)"}

/**/
function colorize( $bloke, $skill ) {
if ($skill >= 2400) { $($bloke).css("background", skill_2400); return ;}
if ($skill >= 2200) { $($bloke).css("background", skill_2200); return ;}
if ($skill >= 2000) { $($bloke).css("background", skill_2000); return ;}
if ($skill >= 1800) { $($bloke).css("background", skill_1800); return ;}
if ($skill >= 1600) { $($bloke).css("background", skill_1600); return ;}
if ($skill >= 1400) { $($bloke).css("background", skill_1400); return ;}
if ($skill >= 1200) { $($bloke).css("background", skill_1200); return ;}
if ($skill >= 1000) { $($bloke).css("background", skill_1000); return ;}
if ($skill >= 800) { $($bloke).css("background", skill_800); return ;}
if ($skill >= 600) { $($bloke).css("background", skill_600); return ;}
if ($skill >= 400) { $($bloke).css("background", skill_400); return ;}
if ($skill >= 0) { $($bloke).css("background", skill_0); return ;}
}

</script>


<script src = "js/seedrandom.js"></script>

contents:

<script>
!function(a,b,c,d,e,f,g,h,i){function j(a){var b,c=a.length,e=this,f=0,g=e.i=e.j=0,h=e.S=[];for(c||(a=[c++]);d>f;)h[f]=f++;for(f=0;d>f;f++)h[f]=h[g=s&g+a[f%c]+(b=h[f])],h[g]=b;(e.g=function(a){for(var b,c=0,f=e.i,g=e.j,h=e.S;a--;)b=h[f=s&f+1],c=c*d+h[s&(h[f]=h[g=s&g+b])+(h[g]=b)];return e.i=f,e.j=g,c})(d)}function k(a,b){var c,d=[],e=typeof a;if(b&&"object"==e)for(c in a)try{d.push(k(a[c],b-1))}catch(f){}return d.length?d:"string"==e?a:a+"\0"}function l(a,b){for(var c,d=a+"",e=0;e<d.length;)b[s&e]=s&(c^=19*b[s&e])+d.charCodeAt(e++);return n(b)}function m(c){try{return o?n(o.randomBytes(d)):(a.crypto.getRandomValues(c=new Uint8Array(d)),n(c))}catch(e){return[+new Date,a,(c=a.navigator)&&c.plugins,a.screen,n(b)]}}function n(a){return String.fromCharCode.apply(0,a)}var o,p=c.pow(d,e),q=c.pow(2,f),r=2*q,s=d-1,t=c["seed"+i]=function(a,f,g){var h=[];f=1==f?{entropy:!0}:f||{};var o=l(k(f.entropy?[a,n(b)]:null==a?m():a,3),h),s=new j(h);return l(n(s.S),b),(f.pass||g||function(a,b,d){return d?(c[i]=a,b):a})(function(){for(var a=s.g(e),b=p,c=0;q>a;)a=(a+c)*d,b*=d,c=s.g(1);for(;a>=r;)a/=2,b/=2,c>>>=1;return(a+c)/b},o,"global"in f?f.global:this==c)};if(l(c[i](),b),g&&g.exports){g.exports=t;try{o=require("crypto")}catch(u){}}else h&&h.amd&&h(function(){return t})}(this,[],Math,256,6,52,"object"==typeof module&&module,"function"==typeof define&&define,"random");
</script>

Answers (1)

2020-06-08

User180435 answers:

script src = "js/seedrandom.js"></script>

<script>
function class_color(){
prng = new Math.seedrandom();
return "hsla(" + ~~(360 * prng()) + "," + "70%,"+"87.5%,1)"}

</script>