# \[feature request\]random pick node

**URL:** <https://discuss.dgraph.io/t/feature-request-random-pick-node/2141>\
**Category:** Users\
**Created:** [January 19, 2018, 6:31am UTC](https://discuss.dgraph.io/t/feature-request-random-pick-node/2141 "2018-01-19T06:31:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yupengfei](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/yupengfei/32/1095_2.png) [@yupengfei](https://discuss.dgraph.io/u/yupengfei)\
**Post date:** [January 19, 2018, 6:31am UTC](https://discuss.dgraph.io/t/feature-request-random-pick-node/2141/1 "2018-01-19T06:31:08Z")

</div>

What I want to do is random pick N node to recommend to the user, now I do it in two query, first query the count of node satisfy the requirement, then I calculate a offset randomly, to implement the feature that random recommendation.

If there is a query like

```auto
q(func: ..., random: N)

```

This query will be much faster.

Blow is the detail of what I have done now.

First, I count all node satisfy the requirement

```auto
{
			me as var(func:eq(user_id, %s)) {
				uname
				A as university_name
				total_score
			}
			var(func: uid(me)) {
				fl as follow {
				}
			}
			TopRecommendationCount(func:eq(university_name, val(A))) @filter(gt(total_score, %d) and not ( uid(me, fl))) {
				total: count(uid)
			}
		}

```

then I calculate a offset randomly, and then another query

```auto
{
			me as var(func:eq(user_id, %s)) {
				uname
				A as university_name
				total_score
			}
			var(func: uid(me)) {
				fl as follow {
				}
			}
			TopRecommendations(func:eq(university_name, val(A)), first: %d, offset: %d) @filter(gt(total_score, %d) and not ( uid(me, fl))) {
				user_id
				uname
				university_name
				total_score 
			}
		}

```

---

<div class="post-metadata">

**Author:** ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)\
**Post date:** [January 21, 2018, 11:10pm UTC](https://discuss.dgraph.io/t/feature-request-random-pick-node/2141/2 "2018-01-21T23:10:10Z")

</div>

Hey @yupengfei

Please open an issue on Github and we can do this at some point.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [February 20, 2018, 11:10pm UTC](https://discuss.dgraph.io/t/feature-request-random-pick-node/2141/3 "2018-02-20T23:10:27Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

See 3226 issue for more details

> <https://github.com/dgraph-io/dgraph/issues/3226>
>
> In \[the close issue\](https://github.com/dgraph-io/dgraph/issues/2335#issue-31430…6192), you provided has(predicate). But we you build a recommend system, you need to recommend M items of N to users, where N is big though to avoid repeat too often, and in that case, you need random.
