OrderByRand returns a term to natively order by a random value.
()
| 394 | |
| 395 | // OrderByRand returns a term to natively order by a random value. |
| 396 | func OrderByRand() func(*Selector) { |
| 397 | return func(s *Selector) { |
| 398 | s.OrderExprFunc(func(b *Builder) { |
| 399 | switch s.Dialect() { |
| 400 | case dialect.MySQL: |
| 401 | b.WriteString("RAND()") |
| 402 | default: |
| 403 | b.WriteString("RANDOM()") |
| 404 | } |
| 405 | }) |
| 406 | } |
| 407 | } |
| 408 | |
| 409 | // ToFunc returns a function that sets the ordering on the given selector. |
| 410 | // This is used by the generated code. |