Search Results

Search found 2 results on 1 pages for 'oregontrail'.

Page 1/1 | 1 

  • Shuffling algorithm with no "self-mapping"?

    - by OregonTrail
    To randomly shuffle an array, with no bias towards any particular permutation, there is the Knuth Fischer-Yeats algorithm. In Python: #!/usr/bin/env python import sys from random import randrange def KFYShuffle(items): i = len(items) - 1 while i > 0: j = randrange(i+1) # 0 <= j <= i items[j], items[i] = items[i], items[j] i = i - 1 return items print KFYShuffle(range(int(sys.argv[1]))) There is also Sattolo's algorithm, which produces random cycles. In Python: #!/usr/bin/env python import sys from random import randrange def SattoloShuffle(items): i = len(items) while i > 1: i = i - 1 j = randrange(i) # 0 <= j <= i-1 items[j], items[i] = items[i], items[j] return items print SattoloShuffle(range(int(sys.argv[1]))) I'm currently writing a simulation with the following specifications for a shuffling algorithm: The algorithm is unbiased. If a true random number generator was used, no permutation would be more likely than any other. No number ends up at its original index. The input to the shuffle will always be A[i] = i for i from 0 to N-1 Permutations are produced that are not cycles, but still meet specification 2. The cycles produced by Sattolo's algorithm meet specification 2, but not specification 1 or 3. I've been working at creating an algorithm that meets these specifications, what I came up with was equivalent to Sattolo's algorithm. Does anyone have an algorithm for this problem?

    Read the article

  • Multiple use of a form before it is submitted

    - by OregonTrail
    I'm new to JavaScript, and trying to figure out the canonical way to do the following. I have a form with some checkboxes and a selector. Let's say the checkboxes are styles of music and the selector is for people's names. I'd like the user to be able to select the styles of music for each of the people's names and then submit the form with all of the data. For example, the user might first check off Classical, Jazz, Rock, and Pop and choose "Joe", then select Jazz, Pop, Country, and Electronica and choose "Jane". So there would have to be two different buttons for "submit person" and "submit form". I would like to: Have a list of the names and their chosen styles populate below the form, for feedback Allow the user to use the form as much as they want, and then submit all the data at the end I get the feeling that using jquery and JSON is perfect for this, but I'm not sure what search terminology to use to figure out how to do this. If it matters, the form will be processed by a Django view in Python.

    Read the article

1