How do I query node sort by randomize?
I don't think this is possible with an entity query directly, but you can alter entity queries after they are converted into select queries.

Add a tag to your entity query and then you can alter it there.

  $nids = \Drupal::entityQuery('node')
    -&gt;condition('type', 'article')
    -&gt;addTag('sort_by_random')
    -&gt;execute();


Then add a query alter function to your custom module using the tag you added.  Drupal's select query even has a built in function to make a query sort on "RAND()":

function mymodule_query_sort_by_random_alter(\Drupal\Core\Database\Query\AlterableInterface $query) {
  $query-&gt;orderRandom();
}


If you're going to have to tag an entity query to alter it, and it's not essential that you use an entity query, you might want to just replace it with a select query.

$query = \Drupal::database()-&gt;select('node_field_data', 'n')
  -&gt;fields('n', ['nid'])
  -&gt;condition('type', 'article')
  -&gt;range(0, 10)
  -&gt;orderRandom();

$results = $query-&gt;execute()-&gt;fetchCol();

if (!empty($results)) {
  $nodes = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;loadMultiple($results);
}