  We propose $\tt RandUCB$, a bandit strategy that builds on theoretically
derived confidence intervals similar to upper confidence bound (UCB)
algorithms, but akin to Thompson sampling (TS), it uses randomization to trade
off exploration and exploitation. In the $K$-armed bandit setting, we show that
there are infinitely many variants of $\tt RandUCB$, all of which achieve the
minimax-optimal $\widetilde{O}(\sqrt{K T})$ regret after $T$ rounds. Moreover,
for a specific multi-armed bandit setting, we show that both UCB and TS can be
recovered as special cases of $\tt RandUCB$. For structured bandits, where each
arm is associated with a $d$-dimensional feature vector and rewards are
distributed according to a linear or generalized linear model, we prove that
$\tt RandUCB$ achieves the minimax-optimal $\widetilde{O}(d \sqrt{T})$ regret
even in the case of infinitely many arms. Through experiments in both the
multi-armed and structured bandit settings, we demonstrate that $\tt RandUCB$
matches or outperforms TS and other randomized exploration strategies. Our
theoretical and empirical results together imply that $\tt RandUCB$ achieves
the best of both worlds.
