Answers.Body: <p>I was unable to find an online tool to do this, but in terms of how, the following appears to be the logic that would be used:</p>
  
  <ul>
  <li>Both white and black pieces would be in the correct starting positions;</li>
  <li>White would start;</li>
  <li>Turns following white's start would be exchanged between white and black;</li>
  <li>Any piece able to move during a turn would be a member of the list of pieces to be randomly selected to move;</li>
  <li>Once a piece was selected, all squares for that piece that are legal moves would be added to the list of possible moves, and a move would be selected randomly from that list;</li>
  <li>Attacks would not take place unless the attack was randomly selected as a move. If an attack does take place, then the attacked pieced would be removed from the board.</li>
  <li>Iterations of randomly selected moves would stop once the number of moves into the game set before generating the board had been reached.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-18T17:57:10.510Z
Answers.Text: I was searching for this as well and was unable to find something that was automatic.
Answers.UserDisplayName: xaisoft
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-18T18:11:13.683Z
Answers.Text: @xaisoft: Clearly me either, though I haven't seen a name for this chess variant either, which would likely help. As you likely know, [Fischerandom chess is related, here's a tool that generates setups](http://www.chessgames.com/perl/fischerandom).
Answers.UserDisplayName: blunders
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-18T17:06:05.527Z
Answers.LastActivityDate: 2012-06-13T16:54:56.087Z
Answers.LastEditDate: 2012-06-13T16:54:56.087Z
Answers.UserDisplayName: blunders
Answers.Body: <p>I stumbled upon Chess Hero.  It looks very nice, but it is not online.  Per the website:</p>
  
  <ol>
  <li>You supply a set of PGN files</li>
  <li>The program picks random positions from the PGN files and challenges you to guess the best move computed by a chess engine</li>
  <li>On every attempt you are given a penalty (the difference in score between your move and the engine best)</li>
  </ol>
  
  <p>The software can be found <a href="http://innokuo.altervista.org/chesshero.html">here</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-19T02:13:55.257Z
Answers.Text: +1 @xaisoft: Interesting, wonder why someone would build a system that's not online. Anyway, as you might guess, this is not really the problem I'm attempting to solve, that being a point-based guess the next move based on archival PGN files; though weighting the random selection of a move on a scale of best to worst was a more advance feature I'd hoped for in the "random opening" game; meaning that you would handicap one-sides opening in a semi-random, yet statistically weighted way.
Answers.UserDisplayName: blunders
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-19T01:01:53.677Z
Answers.LastActivityDate: 2012-06-13T16:53:55.993Z
Answers.LastEditDate: 2012-06-13T16:53:55.993Z
Answers.UserDisplayName: xaisoft
Answers.Body: <p>Find an online database of games.  Choose a random game and a random move in that game.  Voila, an instant realistic and legal position.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-18T21:31:44.210Z
Answers.Text: It's not the same thing, meaning while it's possible the select of the game, and the point within it might be selected randomly -- the openings would not be random. That said, I realize now that the use of "natural" in the body of the question was confusing, so I've replaced it with legal. Also, might note that currently the answer posted by me covers roughly, if not exactly the method of board generation I'm talking about. Thanks of the suggestion, and I agree that if attempt to select a randomly select a "natural" game it'd be the way to go.
Answers.UserDisplayName: blunders
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-18T23:58:35.193Z
Answers.Text: If that's all you need, then what you're talking about would be pretty easy to write.  Given that what we're talking about seems useless, I doubt it exists on the web anywhere.
Answers.UserDisplayName: Tony Ennis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-19T00:32:04.320Z
Answers.Text: So, you're saying that using stats from [chess opening explorer](http://www.chessgames.com/perl/explorer) would be more useful (which is likely true), but I'm saying my way would be more fun, and lead to more creative games.
Answers.UserDisplayName: blunders
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-19T00:44:36.527Z
Answers.Text: @blunders no, I'm saying that if you want realistic positions, pulling them from real games would be easy. If you want random positions, generating them randomly would be easy.
Answers.UserDisplayName: Tony Ennis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2012-05-18T21:21:33.970Z
Answers.LastActivityDate: 2012-06-13T16:55:09.410Z
Answers.LastEditDate: 2012-06-13T16:55:09.410Z
Answers.UserDisplayName: Tony Ennis
Answers.Body: <p>I've actually programmed precisely that in PHP to test a hypothesis two days ago.
  If you're interested, I've uploaded the code to github for you: <a href="https://github.com/dennisvink/php-random-chess-move-generator" rel="nofollow">https://github.com/dennisvink/php-random-chess-move-generator</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-11-11T20:55:12.780Z
Answers.LastActivityDate: 2013-11-11T20:55:12.780Z
Answers.UserDisplayName: Dennis
Answers.Body: <p>Besides the two ways already mentioned:</p>
  
  <ol>
  <li>Pick a random position from a database.</li>
  <li>Play a random amount of random moves.</li>
  </ol>
  
  <p>We should also mention the most simple:</p>
  
  <ol>
  <li>Generate a totally random position. Validate it. If not legal repeat.</li>
  </ol>
  
  <p>You should be able to find lots of tools for analyzing if a position is legal. (E.g. exactly one king on each side etc.)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-03-02T08:53:28.137Z
Answers.LastActivityDate: 2014-03-02T08:53:28.137Z
Answers.UserDisplayName: Thomas Ahle
Answers.Body: <p>How about using live games from lichess? Here is an <a href="http://en.lichess.org/api/game/JdQW2JbI?with_fens=1" rel="nofollow">example</a> call to the server. See the docs for pulling a list of users currently playing. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-21T02:07:45.620Z
Answers.LastActivityDate: 2016-03-21T02:07:45.620Z
Answers.UserDisplayName: Peter Cotton
Answers.Body: <p>I think <a href="http://lichess.org" rel="nofollow noreferrer">Lichess</a> training do just that. It's software take a game position from it's database and challenge you to pick the best one based on Stockfish analysis.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-01-13T02:04:53.017Z
Answers.LastActivityDate: 2020-03-03T16:03:42.333Z
Answers.LastEditDate: 2020-03-03T16:03:42.333Z
Answers.UserDisplayName: motobói
Body: <p>Is there a free online website that attempts to generate "legal" random chess setups X amount of moves into the game?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-12-08T14:42:00.297Z
Comments.Text: How random do you want them ? Equiprobable ? Do you need a series of moves to lead to that position ? If that's random, what sense does “​X moves into the game” exactly make ? **In what format do you want the result ?** (FEN, diagram, series of moves…)
Comments.UserDisplayName: Nikana Reklawyks
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-05-18T17:51:09.707Z
Comments.Text: I'm curious why you would find such a tool useful
Comments.UserDisplayName: Valentin Brasso
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2012-05-18T18:08:14.873Z
Comments.Text: @altvali: No reason.
Comments.UserDisplayName: blunders
Tags: <learning><software>
Title: How can I generate legal random chess setups?
ThreadText: # How can I generate legal random chess setups?
  
  (Asked by: username_0 on 2012-05-18)
  
  Is there a free online website that attempts to generate "legal" random chess setups X amount of moves into the game?
  
  **Tags:** learning, software
  
  > **Comments:**
  > **username_2**: I'm curious why you would find such a tool useful  
  > **username_0**: @altvali: No reason.  
  > **username_1**: How random do you want them ? Equiprobable ? Do you need a series of moves to lead to that position ? If that's random, what sense does “​X moves into the game” exactly make ? **In what format do you want the result ?** (FEN, diagram, series of moves…)  
  
  ---
  
  ## 7 answers
  
  ### Answer by username_0 on 2012-05-18. Score: 1 | Accepted answer
  
  I was unable to find an online tool to do this, but in terms of how, the following appears to be the logic that would be used:
  
  * Both white and black pieces would be in the correct starting positions;
  * White would start;
  * Turns following white's start would be exchanged between white and black;
  * Any piece able to move during a turn would be a member of the list of pieces to be randomly selected to move;
  * Once a piece was selected, all squares for that piece that are legal moves would be added to the list of possible moves, and a move would be selected randomly from that list;
  * Attacks would not take place unless the attack was randomly selected as a move. If an attack does take place, then the attacked pieced would be removed from the board.
  * Iterations of randomly selected moves would stop once the number of moves into the game set before generating the board had been reached.
  
  > **Comments:**
  > **username_3**: I was searching for this as well and was unable to find something that was automatic.  
  > **username_0**: @username_3: Clearly me either, though I haven't seen a name for this chess variant either, which would likely help. As you likely know, [Fischerandom chess is related, here's a tool that generates setups](http://www.chessgames.com/perl/fischerandom).  
  
  ---
  
  ### Answer by username_3 on 2012-05-19. Score: 8
  
  I stumbled upon Chess Hero. It looks very nice, but it is not online. Per the website:
  
  1. You supply a set of PGN files
  2. The program picks random positions from the PGN files and challenges you to guess the best move computed by a chess engine
  3. On every attempt you are given a penalty (the difference in score between your move and the engine best)
  
  The software can be found [here](http://innokuo.altervista.org/chesshero.html).
  
  > **Comments:**
  > **username_0**: +1 @username_3: Interesting, wonder why someone would build a system that's not online. Anyway, as you might guess, this is not really the problem I'm attempting to solve, that being a point-based guess the next move based on archival PGN files; though weighting the random selection of a move on a scale of best to worst was a more advance feature I'd hoped for in the "random opening" game; meaning that you would handicap one-sides opening in a semi-random, yet statistically weighted way.  
  
  ---
  
  ### Answer by username_4 on 2012-05-18. Score: 6
  
  Find an online database of games. Choose a random game and a random move in that game. Voila, an instant realistic and legal position.
  
  > **Comments:**
  > **username_0**: It's not the same thing, meaning while it's possible the select of the game, and the point within it might be selected randomly -- the openings would not be random. That said, I realize now that the use of "natural" in the body of the question was confusing, so I've replaced it with legal. Also, might note that currently the answer posted by me covers roughly, if not exactly the method of board generation I'm talking about. Thanks of the suggestion, and I agree that if attempt to select a randomly select a "natural" game it'd be the way to go.  
  > **username_4**: If that's all you need, then what you're talking about would be pretty easy to write.  Given that what we're talking about seems useless, I doubt it exists on the web anywhere.  
  > **username_0**: So, you're saying that using stats from [chess opening explorer](http://www.chessgames.com/perl/explorer) would be more useful (which is likely true), but I'm saying my way would be more fun, and lead to more creative games.  
  > **username_4**: @username_0 no, I'm saying that if you want realistic positions, pulling them from real games would be easy. If you want random positions, generating them randomly would be easy.  
  
  ---
  
  ### Answer by username_5 on 2013-11-11. Score: 2
  
  I've actually programmed precisely that in PHP to test a hypothesis two days ago.
  If you're interested, I've uploaded the code to github for you: <https://github.com/dennisvink/php-random-chess-move-generator>
  
  
  ---
  
  ### Answer by username_6 on 2014-03-02. Score: 0
  
  Besides the two ways already mentioned:
  
  1. Pick a random position from a database.
  2. Play a random amount of random moves.
  
  We should also mention the most simple:
  
  1. Generate a totally random position. Validate it. If not legal repeat.
  
  You should be able to find lots of tools for analyzing if a position is legal. (E.g. exactly one king on each side etc.)
  
  
  ---
  
  ### Answer by username_7 on 2016-03-21. Score: -2
  
  How about using live games from lichess? Here is an [example](http://en.lichess.org/api/game/JdQW2JbI?with_fens=1) call to the server. See the docs for pulling a list of users currently playing.
  
  
  ---
  
  ### Answer by username_8 on 2017-01-13. Score: -2
  
  I think [Lichess](http://lichess.org) training do just that. It's software take a game position from it's database and challenge you to pick the best one based on Stockfish analysis.
  
  
  ---
  
  