How do I query node sort by randomize? I want to get all articles content type, but I want to get it randomize, how can I do that? Refer to my code below:

$nids = \Drupal::entityQuery('node')-&gt;condition('type', 'articles')-&gt;sort('RAND()')-&gt;execute();


I'm using drupal 8
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);
}