File size: 418 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package allocation

import (
	"math/rand/v2"

	"github.com/pinchtab/pinchtab/internal/bridge"
)

// Random selects a random candidate.
type Random struct{}

func (r *Random) Name() string { return "random" }

func (r *Random) Select(candidates []bridge.Instance) (bridge.Instance, error) {
	if len(candidates) == 0 {
		return bridge.Instance{}, ErrNoCandidates
	}
	return candidates[rand.IntN(len(candidates))], nil
}