cubing/scramble is the part of cubing.js that lets you generate fair random-state scrambles.

Random Scramble

Use randomScrambleForEvent to get a scramble. This returns a JavaScript Promise for an Alg, which is easiest to use with await.

import { randomScrambleForEvent } from "cubing/scramble";

const scramble = await randomScrambleForEvent("333"); console.log(scramble.toString());
"F' R' F' U2 B D' L' U F R B' R2 F' L2 F2 L2 D2 B R2 L2 F'"

You can generate scrambles for all official WCA events:

import { randomScrambleForEvent } from "cubing/scramble";

(await randomScrambleForEvent("333")).log();
(await randomScrambleForEvent("333bf")).log();
(await randomScrambleForEvent("333fm")).log();
(await randomScrambleForEvent("222")).log();
(await randomScrambleForEvent("444")).log();
(await randomScrambleForEvent("777")).log();
(await randomScrambleForEvent("sq1")).log();
(await randomScrambleForEvent("minx")).log();
(await randomScrambleForEvent("clock")).log();
Alg {} "R' F2 … L U'" Alg {} "R' B2 … R Fw' Dw" Alg {} "R' U' F D … L' R' U' F" Alg {} "Fw2 Lw2 L …" Alg {} "(-2, 6) / …" Alg {} "R-- D++ R++ D-- …" Alg {} "UR1- DR1+ …"

Note that:

With <twisty-player>

You can assign a scramble or a scramble Promise to <twisty-player>. Here is a simple way to display a scramble alg with an associated player:

<twisty-alg-viewer for="main-player"></twisty-alg-viewer>
<twisty-player id="main-player"></twisty-player>

<script type="module">
  import "cubing/twisty";
  import { randomScrambleForEvent } from "cubing/scramble";
  const scramblePromise = randomScrambleForEvent("333");
  document.querySelector("#main-player").alg = scramblePromise;

Try it.