# Random SortScript with Session ID

**URL:** <https://discuss.elastic.co/t/random-sortscript-with-session-id/231307>\
**Category:** Elasticsearch\
**Created:** [May 6, 2020, 9:36am UTC](https://discuss.elastic.co/t/random-sortscript-with-session-id/231307 "2020-05-06T09:36:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulMcGregory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paulmcgregory/32/67782_2.png) [@PaulMcGregory](https://discuss.elastic.co/u/PaulMcGregory)\
**Post date:** [May 6, 2020, 9:36am UTC](https://discuss.elastic.co/t/random-sortscript-with-session-id/231307/1 "2020-05-06T09:36:29Z")

</div>

Hi,

i am trying to get a random sorting by using this CustomSortScript

`'source' => '(doc[\'isPremium\'].value == false ? 0 : 1 ) * (doc[\'uid\'].value * ' . substr($sessionCrc, 0, 5 ) . ')'`

It works and it is getting a random ID, but there is a logik problem. An upper incrementalID is getting an another ID like with different sessions, but the sorting of the uid \* Session ID is always the same

I thinks, that if I will truncate the incrementel IDs to 1 or 2 digits, i am getting more fuzziy numbers -\> result: random sorting

How can I solve it?  
Is there maybe an another way to solve it?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 3, 2020, 9:36am UTC](https://discuss.elastic.co/t/random-sortscript-with-session-id/231307/2 "2020-06-03T09:36:30Z")

</div>

Closed on June 3, 2020, 9:36am UTC

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