Alternative to Web Service Random Number in JavaScript | XM Community
Skip to main content

I previously had coded a conjoint experiment in JS within Qualtrics that worked rather successfully. Qualtrics took down its Web Service random number generator however, and the conjoint no longer works as a result.
I've attempted to use the embedded data and piped text random number generator that Qualtrics offers as an alternative, but it does not seem to be working with each randomization of the conjoint simply offering the exact same outcomes.
Qualtrics.SurveyEngine.addOnload(function()
{
// import seeded random number generator code
!function(a,b){function c(c,j,k){var n=n];j=1==j?{entropy:!0}:j||{};var s=g(f(j.entropy?oc,i(a)]:null==c?h():c,3),n),t=new d(n),u=function(){for(var a=t.g(m),b=p,c=0;q>a;)a=(a+c)*l,b*=l,c=t.g(1);for(;a>=r;)a/=2,b/=2,c>>>=1;return(a+c)/b};return u.int32=function(){return 0|t.g(4)},u.quick=function(){return t.g(4)/4294967296},u6"double"]=u,g(i(t.S),a),(j.pass||k||function(a,c,d,f){return f&&(f.S&&e(f,t),a.state=function(){return e(t,{})}),d?(bdo]=a,c):a})(u,s,"global"in j?j.global:this==b,j.state)}function d(a){var b,c=a.length,d=this,e=0,f=d.i=d.j=0,g=d.S=d];for(c||(a=|c++]);l>e;)gee]=e++;for(e=0;l>e;e++)g+e]=gef=s&f+a&e%c]+(b=g(e])],g)f]=b;(d.g=function(a){for(var b,c=0,e=d.i,f=d.j,g=d.S;a--;)b=g)e=s&e+1],c=c*l+g*s&(gse]=gef=s&f+b])+(g)f]=b)];return d.i=e,d.j=f,c})(l)}function e(a,b){return b.i=a.i,b.j=a.j,b.S=a.S.slice(),b}function f(a,b){var c,d=c],e=typeof a;if(b&&"object"==e)for(c in a)try{d.push(f(a(c],b-1))}catch(g){}return d.length?d:"string"==e?a:a+"\\0"}function g(a,b){for(var c,d=a+"",e=0;e
Math.seedrandom('${e://Field/seed1}');


// store values as embedded data fields
Qualtrics.SurveyEngine.setEmbeddedData('traits1A', traits_a.join("|"));
Qualtrics.SurveyEngine.setEmbeddedData('traits1B', traits_b.join("|"));


In between the seed and storing the profiles the variables are set and html values are set.
I don't know why the embedded data piped text RNG isn't working in this instance or if there's something else wrong with my code, but when the seed is included the randomization stops working. As well, it no longer saves my profiles correctly into embedded data.
This conjoint is largely based off of Kyle Dropp's work and this great guide here: https://github.com/leeper/conjoint-example
Any help would be greatly appreciated.

@sh25 - i am experiencing a similar issue, were you able to find a way to handle it? 


Leave a Reply