Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.games.development.programming.algorithms > #37

Re: Shuffling

Path csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Mok-Kong Shen <mok-kong.shen@t-online.de>
Newsgroups comp.games.development.programming.algorithms
Subject Re: Shuffling
Date Wed, 01 Aug 2012 20:14:05 +0200
Organization albasani.net
Lines 52
Message-ID <jvbrl7$h5j$1@news.albasani.net> (permalink)
References <jv5p0u$qid$1@news.albasani.net>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net xgOexss7tupvsaCzDoh528q0XmW3kuTa2pDwzM0u/5RzLPpBPIUV+kuXokOZkAV/fFiJwmqpc+NsEI2TqE4ZNw==
NNTP-Posting-Date Wed, 1 Aug 2012 18:14:00 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="TYQmutG+6usGlQybsD5SR+R15WsixZeAEo3vUxYuqu7Q7cUfbepXl9uxoY+9jiQUWjPeZcxqlIkkb3AuETQYaK92o4OjlfM3njyqjdX/Ye2CKT5fjmdsXYg19LdBxE3N"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0
In-Reply-To <jv5p0u$qid$1@news.albasani.net>
Cancel-Lock sha1:H8Fjm8BKc652tzr1oZCqGUgDsiw=
Xref csiph.com comp.games.development.programming.algorithms:37

Show key headers only | View raw


Am 30.07.2012 12:52, schrieb Mok-Kong Shen:
[snip]
> I have done some small amount of experiments but I don't think
> to have yet found a really optimal permutation operation.

A presumably not too bad, though I think yet sub-optimal, scheme
I found sofar is as follow:

Let n be the length of the list to be permuted and kn be a point of
division of the list into two sections. One applies riffle shuffle
to each section and then reverse the ordering of the whole.

It seems to me that, if kn is (randomly chosen and) located in the
middle half of the list, then the permutation effected is a sufficiently
"random" one in some sense.

Perhaps someone could give hints on improvements or provide a similar
but better scheme. For those who like to try out mine, I am attaching
a Python code below.

M. K. Shen

-----------------------------------------------------------

def makecards(n):
   cards=[]
   for i in range(n):
     cards+=[i]
   return(cards)

def riffle(cards,n):
   newcards=[]
   nh=n//2
   for i in range(nh):
     newcards=newcards+[cards[nh+i]]+[cards[i]]
   if nh*2<n:
     newcards+=[cards[n-1]]
   return(newcards)

def newshuffle(cards,kn,n):
   newcards=riffle(cards[0:kn],kn)+riffle(cards[kn:n],n-kn)
   newcards.reverse()
   return(newcards)

# example:

n=52
cards=makecards(n)
kn=18
newcards=newshuffle(cards,kn,n)
print(newcards)

Back to comp.games.development.programming.algorithms | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Shuffling Mok-Kong Shen <mok-kong.shen@t-online.de> - 2012-07-30 12:52 +0200
  Re: Shuffling Mok-Kong Shen <mok-kong.shen@t-online.de> - 2012-08-01 20:14 +0200
  Re: Shuffling hexxial <hexxial@gmail.com> - 2013-01-20 22:58 +0000

csiph-web