Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement a random shuffle algorithm

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to achieve a random shuffle algorithm". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to achieve a random shuffle algorithm" can help you solve the problem.

Introduction

Have you ever had similar troubles? Want to take several non-repeating elements from a list, but don't know how to repeat them? A method called random shuffle is provided here.

Random shuffle principle

Shuffle has the meaning of shuffling, this method is also similar to shuffling, taking a position randomly from the prefix of a list and swapping it at the end of the prefix, so that for each bit, it is similar to shuffling it randomly into a position in front of it, so that the whole list can be messed up into a random distribution. Finally, we only need to take the pre-iii bits of the list after disruption, that is, it is not repeated.

Implement template vector my_random_shuffle (vector input) {static mt19937 rnd (time (NULL)); for (uint64_t iTunes 1; I)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report