{"id":25542,"date":"2021-11-23T08:56:38","date_gmt":"2021-11-23T03:26:38","guid":{"rendered":"https:\/\/python-programs.com\/?p=25542"},"modified":"2021-11-23T08:56:38","modified_gmt":"2021-11-23T03:26:38","slug":"python-random-shuffle-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-random-shuffle-method-with-examples\/","title":{"rendered":"Python Random shuffle() Method with Examples"},"content":{"rendered":"

Random shuffle() Method in Python:<\/strong><\/p>\n

The shuffle() method reorganizes the order of items in a sequence, such as a list.<\/p>\n

Note:<\/strong> Please keep in mind that this method modifies the original list and does not return a new list.<\/p>\n

Syntax:<\/strong><\/p>\n

random.shuffle(sequence, function)<\/pre>\n

Parameters<\/strong><\/p>\n

sequence:<\/strong> This is Required. It could be any sequence.<\/p>\n

function:<\/strong> This is Optional. The name of a function that produces a value between 0.0 and 1.0.
\nIf no function is specified, the random() function will be used.<\/p>\n

Return Value:<\/strong> This method produces no output.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [\"good\", \"morning\", \"Btechgeeks\"]<\/pre>\n

Output:<\/strong><\/p>\n

Given list After shuffling : ['Btechgeeks', 'morning', 'good']<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [10, 20, 30, 40]<\/pre>\n

Output:<\/strong><\/p>\n

Given list After shuffling : [20, 40, 30, 10]<\/pre>\n

Random shuffle() Method with Examples in Python<\/h2>\n