Tutorials  Articles  Notifications  Login  Signup


RK

Rajan Kumar

Founder at HackersFriend Updated Jan. 23, 2019, 12:04 a.m. ⋅ 1250 views

Shuffle elements of an Array most efficient way , Fisher Yates shuffle algorithm


Problem:

You are given an array of N elements, shuffle elements of this array in such a way that, occurance of any element at any position is equally likely.

Given:

A rand() function that returns any value between 0.0 to 1.0 randomly and a floor() function that gives significant integer from any given float value.

 

Soltuion: 

We'll use Fisher Yates Algorithm to solve this problem. you can watch explanation in video.

 



HackerFriend Logo

Join the community of 1 Lakh+ Developers

Create a free account and get access to tutorials, jobs, hackathons, developer events and neatly written articles.


Create a free account