Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
at v4.14-rc6 41 lines 946 B view raw
1#include <linux/bitops.h> 2#include <linux/kernel.h> 3#include <linux/random.h> 4#include <linux/slab.h> 5#include <linux/types.h> 6 7#include "drm_random.h" 8 9static inline u32 drm_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state) 10{ 11 return upper_32_bits((u64)prandom_u32_state(state) * ep_ro); 12} 13 14void drm_random_reorder(unsigned int *order, unsigned int count, 15 struct rnd_state *state) 16{ 17 unsigned int i, j; 18 19 for (i = 0; i < count; ++i) { 20 BUILD_BUG_ON(sizeof(unsigned int) > sizeof(u32)); 21 j = drm_prandom_u32_max_state(count, state); 22 swap(order[i], order[j]); 23 } 24} 25EXPORT_SYMBOL(drm_random_reorder); 26 27unsigned int *drm_random_order(unsigned int count, struct rnd_state *state) 28{ 29 unsigned int *order, i; 30 31 order = kmalloc_array(count, sizeof(*order), GFP_KERNEL); 32 if (!order) 33 return order; 34 35 for (i = 0; i < count; i++) 36 order[i] = i; 37 38 drm_random_reorder(order, count, state); 39 return order; 40} 41EXPORT_SYMBOL(drm_random_order);