(.+?)<\/h[1-6]>)|(\[toc\]<\/p>)/g,(function(n,c,u,i,p){if("
[toc]
"===n)o.push({type:"toc"});else{p=p.replace(/<[^>]+>/g,"");var f={anchor:i,level:Number(u),text:p};r&&r.push(f),o.push(function(r){for(var n=1;arguments.length>n;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(o,!0).forEach((function(t){e(r,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(o).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))}))}return r}({type:"header"},f))}return""}));var c=[];return o.forEach((function(e,t){if("toc"===e.type)if(o[t+1]&&"header"===o[t+1].type){for(var r=[],n=o[t+1].level,u=t+1;o.length>u&&"toc"!==o[u].type;u++){o[u].level===n&&r.push(o[u])}c.push(r)}else c.push([])})),n=n.replace(/\[toc\]<\/p>[\n]*/g,(function(){var e=c.shift();return e&&e.length?"
".concat(e.map((function(e){var t=e.text;return'- ').concat(t,"
")})).join(""),"
\n"):""}))}}]}}}));
diff --git a/public/scripts/macros.js b/public/scripts/macros.js
index e68688fd5..503ae2553 100644
--- a/public/scripts/macros.js
+++ b/public/scripts/macros.js
@@ -1,4 +1,4 @@
-import { Handlebars, moment } from '../lib.js';
+import { Handlebars, moment, seedrandom } from '../lib.js';
import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams } from '../script.js';
import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js';
import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';
@@ -330,7 +330,7 @@ function randomReplace(input, emptyListPlaceholder = '') {
if (list.length === 0) {
return emptyListPlaceholder;
}
- const rng = new Math.seedrandom('added entropy.', { entropy: true });
+ const rng = seedrandom('added entropy.', { entropy: true });
const randomIndex = Math.floor(rng() * list.length);
return list[randomIndex];
});
@@ -359,8 +359,8 @@ function pickReplace(input, rawContent, emptyListPlaceholder = '') {
// We build a hash seed based on: unique chat file, raw content, and the placement inside this content
// This allows us to get unique but repeatable picks in nearly all cases
const combinedSeedString = `${chatIdHash}-${rawContentHash}-${offset}`;
- const finalSeed = getStringHash(combinedSeedString);
- const rng = new Math.seedrandom(finalSeed);
+ const finalSeed = getStringHash(combinedSeedString).toString();
+ const rng = seedrandom(finalSeed);
const randomIndex = Math.floor(rng() * list.length);
return list[randomIndex];
});