Replies: 1 comment
-
Create an environment variable named: guid Then put the following code in your Pre-request Script tab: var lut = [];
for (var i=0; i<256; i++) {
lut[i] = (i<16?'0':'')+(i).toString(16);
}
function e7()
{
var d0 = Math.random()*0xffffffff|0;
var d1 = Math.random()*0xffffffff|0;
var d2 = Math.random()*0xffffffff|0;
var d3 = Math.random()*0xffffffff|0;
return lut[d0&0xff]+lut[d0>>8&0xff]+lut[d0>>16&0xff]+lut[d0>>24&0xff]+'-'+
lut[d1&0xff]+lut[d1>>8&0xff]+'-'+lut[d1>>16&0x0f|0x40]+lut[d1>>24&0xff]+'-'+
lut[d2&0x3f|0x80]+lut[d2>>8&0xff]+'-'+lut[d2>>16&0xff]+lut[d2>>24&0xff]+
lut[d3&0xff]+lut[d3>>8&0xff]+lut[d3>>16&0xff]+lut[d3>>24&0xff];
}
const guid = e7();
pw.env.set("guid", guid); Math.random() is definitely not what should be used for generating uuid's. Instead importing Crypto or Uuid would be better but that's not possible with the current Javascript implementation we have to work with...as far as I know. However, this should suffice unless you're generating thousands. You can read up on this UUID technique from this SO article here: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to get a new GUID or current UNIX timestamp so that I can embed them into my scripts or header? Something like {{$guid}} or {{$timestamp}}?
Beta Was this translation helpful? Give feedback.
All reactions