Pick random node

Hello Dgraph team,

Picking a random has already been mentioned here and on github, but no feature request ticket seems to have been created.

I’m still in the need of such a feature as it would greatly improve:

  • Performances because I currently need to do random queries twice (in a transaction): First to count nodes, second to set one or more random offsets. My biggest and slowest query right now is to do matchmaking in my game, and I have to do it twice each time.
  • Code readability because my current solution requires a big function.

The syntax could be similar to first and offset keywords: random: 3 which would mean we want to pick 3 different random nodes from the current result set. It would perfectly work with offset and first to select the range before picking random nodes.

Please consider my request, I’m sure many projects would benefit from it :slightly_smiling_face:

This may be a side effect of fixing Inconsistent response of sort as a result of indexing of a predicate when we get round to it.