473,320 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to shuffle elements of array

i want to shuffle the elements of an array without using random and shuffle functions.any one please help me.
ex:
input:a[1,2,3,4,5]
ouput:a[2,5,3,1,4]
Aug 17 '07 #1
1 4209
bartonc
6,596 Expert 4TB
i want to shuffle the elements of an array without using random and shuffle functions.any one please help me.
ex:
input:a[1,2,3,4,5]
ouput:a[2,5,3,1,4]
Expand|Select|Wrap|Line Numbers
  1. >>> numList = range(25)
  2. >>> numList
  3. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
  4. >>> dd = dict(zip(map(str, numList),numList))
  5. >>> [int(k) for k in dd.keys()]
  6. [24, 20, 21, 22, 23, 1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 17, 16, 19, 18]
  7. >>> 
Aug 17 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: JC | last post by:
I am very new to programming and learning on my own. Why do I keep getting duplicate values using this code? I want to shuffle a deck of 52 cards. The logic seems right to me. Randomize For...
24
by: Joerg Schuster | last post by:
Hello, I am looking for a method to "shuffle" the lines of a large file. I have a corpus of sorted and "uniqed" English sentences that has been produced with (1): (1) sort corpus | uniq >...
6
by: CaseyB | last post by:
If I wanted to create a game like Solitaire that would first randomly shuffle a deck of cards, I figured out that all I had to use is the Random() class or rnd and make sure I use the Randomize...
4
by: Pratik | last post by:
For the time being, I'm doing a simple swap method for my deck of cards using the random number generator in cstdlib. I've created a dynamic array of a type class Card. When I go to shuffle it and...
9
by: Tuxedo | last post by:
I'd like to reorganize the third, fourth, fifth and sixth, as well as any elements thereafter in an array in random order: var a = new...
25
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py...
4
by: Aamir Mahmood | last post by:
Hi everyone, I have to write a function to shuffle a collection. If anyone has any idea on how to implement it please share with me. The signature of function is: ICollection...
2
by: rubyhuang | last post by:
the problem is A standard pack of cards can be represented as an array of 52 integers with each number representing a standard card. Thus: 0 1 2 3 4 5 6 7 8 9 10 11 12.....39 40 41 42 43 44 45 46...
11
by: whodgson | last post by:
I`m trying to write a shuffle function to shuffle a sorted array with an even number of elements but it won`t print past the first 2 elements as shown below. When i print the temp array it only...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.