How to select random vertices in Gremlin

181 views
Skip to first unread message

Khaled Bakhit

unread,
Feb 25, 2015, 4:04:55 PM2/25/15
to gremli...@googlegroups.com

I'm still at my earlier stages with graphs and gremlin.

Is it possible to randomly select graph vertices in Gremlin?

Consider the following pipeline that gets the cars owned by a user's friend:

u.out('Friend')[0..9].out('Drives').map()

But this code is only executed against the first 10 friends every time. How can I make the selection random efficiently?

Thank you for your time :)

Kelvin Lawrence

unread,
Feb 25, 2015, 4:44:08 PM2/25/15
to gremli...@googlegroups.com
Others may suggest betters ways, but you could code something like:

n = (Math.random()*100).round()
u.out('Friend')[0..n].out('Drives').map()

Daniel Kuppitz

unread,
Feb 27, 2015, 11:54:32 AM2/27/15
to gremli...@googlegroups.com
Maybe start by reading the docs. There's a step called random() that helps you out in this scenario.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/a5602837-b7c3-46f2-9762-2ee827b0c696%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages