{"id":22513576,"url":"https://github.com/emahtab/shuffle-an-array","last_synced_at":"2026-02-17T22:02:18.096Z","repository":{"id":79525792,"uuid":"259994811","full_name":"eMahtab/shuffle-an-array","owner":"eMahtab","description":"Shuffle an array","archived":false,"fork":false,"pushed_at":"2020-04-29T17:30:00.000Z","size":1,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T06:23:35.118Z","etag":null,"topics":["array","fisher-yates-shuffle","leetcode","problem-solving","shuffle"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-04-29T17:28:34.000Z","updated_at":"2020-04-29T17:31:18.000Z","dependencies_parsed_at":"2023-05-10T17:30:55.870Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/shuffle-an-array","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/shuffle-an-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fshuffle-an-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fshuffle-an-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fshuffle-an-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fshuffle-an-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/shuffle-an-array/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fshuffle-an-array/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29559961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","fisher-yates-shuffle","leetcode","problem-solving","shuffle"],"created_at":"2024-12-07T03:13:32.444Z","updated_at":"2026-02-17T22:02:18.090Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Shuffle an array\n## https://leetcode.com/problems/shuffle-an-array\n\nShuffle a set of numbers without duplicates.\n```\nExample:\n\n// Init an array with set 1, 2, and 3.\nint[] nums = {1,2,3};\nSolution solution = new Solution(nums);\n\n// Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3] must equally likely to be returned.\nsolution.shuffle();\n\n// Resets the array back to its original configuration [1,2,3].\nsolution.reset();\n\n// Returns the random shuffling of array [1,2,3].\nsolution.shuffle();\n```\n\n# Implementation :\n```java\nclass Solution {\n    private int[] array;\n    private int[] cloned;\n    private Random rand = new Random();\n    \n    public Solution(int[] nums) {\n        array = nums;\n        cloned = nums.clone();\n    }\n    \n    private List\u003cInteger\u003e getArrayCopy() {\n        List\u003cInteger\u003e asList = new ArrayList\u003cInteger\u003e();\n        for (int i = 0; i \u003c array.length; i++) {\n            asList.add(array[i]);\n        }\n        return asList;\n    }\n    \n    /** Resets the array to its original configuration and return it. */\n    public int[] reset() {\n        return cloned;\n    }\n    \n    /** Returns a random shuffling of the array. */\n    public int[] shuffle() {\n        List\u003cInteger\u003e aux = getArrayCopy();\n        for (int i = 0; i \u003c array.length; i++) {\n            int removeIdx = rand.nextInt(aux.size());\n            array[i] = aux.get(removeIdx);\n            aux.remove(removeIdx);\n        }\n\n        return array;\n    }\n}\n\n/**\n * Your Solution object will be instantiated and called as such:\n * Solution obj = new Solution(nums);\n * int[] param_1 = obj.reset();\n * int[] param_2 = obj.shuffle();\n */\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fshuffle-an-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fshuffle-an-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fshuffle-an-array/lists"}