• Welcome to SpeedSolving.com — the world’s largest puzzle community!

    You’re currently browsing as a guest, which means you have limited access to discussions, resources, member profiles, and community features.

    Join 50,000+ cubers and puzzle enthusiasts from around the world to ask questions, share solves, improve faster, and be part of the community.

    Registration is free, fast, and easy — create your account today.

    Already a member? Log in here to hide this message and start participating.

Programing a Scramble Generator with PHP

Humble Cuber

Veteran
Joined
Mar 26, 2020
Messages
337
Location
Somewhere on Earth
YouTube
Visit Channel
Hi, I am currently trying to make my own speedcubing timer website, I already have the stopwatch design down for the timer itself, but I've been having some trouble with creating a random string generator via PHP for the scrambles the problem is that those different variables are being pushed together, so rather than a normal looking scramble it comes out looking something like this "R22UB2BU2R"
this is the current code I have, if you can please give me some help on how to make each piece of notation a separate variable that would be greatly appreciated.

<?php
function = ranSrtGen(){

}
$result = "";
$chars = "R B U L F D R2 B2 U2 L2 F2 D2";
$charArray = str_split($chars);
for($i = 0; $i < 18; $i++){
$randItem = array_rand($charArray);
$result .= "".$charArray[$randItem];
}
echo $result
?>
 
Why PHP and not JavaScript? The timer will be hitting the server for every single scramble generated if you're generating the scrambles on the server.

Also:
1. Try appending a single space (" ") after each move. In the final result, you will have an extraneous space at the end of the scramble, but if it's being thrown into HTML the trailing space doesn't matter.
2. You're missing the anticlockwise moves.
3. Random-move scrambles should be at least 25 moves long.
 
Why PHP and not JavaScript? The timer will be hitting the server for every single scramble generated if you're generating the scrambles on the server.

Also:
1. Try appending a single space (" ") after each move. In the final result, you will have an extraneous space at the end of the scramble, but if it's being thrown into HTML the trailing space doesn't matter.
2. You're missing the anticlockwise moves.
3. Random-move scrambles should be at least 25 moves long.
Thanks, Javascript I think could be easier to incorporate as well.
 
Hi, I am currently trying to make my own speedcubing timer website, I already have the stopwatch design down for the timer itself, but I've been having some trouble with creating a random string generator via PHP for the scrambles the problem is that those different variables are being pushed together, so rather than a normal looking scramble it comes out looking something like this "R22UB2BU2R"
this is the current code I have, if you can please give me some help on how to make each piece of notation a separate variable that would be greatly appreciated.

<?php
function = ranSrtGen(){

}
$result = "";
$chars = "R B U L F D R2 B2 U2 L2 F2 D2";
$charArray = str_split($chars);
for($i = 0; $i < 18; $i++){
$randItem = array_rand($charArray);
$result .= "".$charArray[$randItem];
}
echo $result
?>
1. Don't use PHP.
If you really have to use PHP then
2. str_split turns "R2 F2 B2" into array("R","2"," ","F","2"," ","B","2"), which is not what you want. Use
Code:
$charArray = explode(" ",$chars);
3. Add a space at the end of each move, so
Code:
$result .= " ".$charArray[$randItem];
Live Instance of your scrambler running with improvements
 
Last edited:
Good luck with your project.

Do share the github link if you plan to open source your php written scramble generator project, U S U M' U M U' S' M' U' M U' .
 
Back
Top