Search
Code Directory
 ASP
 ASP.NET
 C/C++
 CFML
 CGI/PERL
 Delphi
 Development
 Flash
 HTML
 Java
 JavaScript
 Pascal
 PHP
 Python
 SQL
 Tools
 Visual Basic & VB.NET
 XML
New Code
Database Workbench Pro 5.4.6
Extensibility Studio 3.0
Bytescout Spreadsheet SDK 3.0.0.1699
Magento 2 Admin Mobile App 1.0
Data Compare for MySQL 5.3
ODBC Driver for Zoho CRM 1.3
ODBC Driver for SugarCRM 1.3
Bytescout PDF To HTML SDK 9.0.0.3079
Azizi search engine script PHP 4.1.10
TaxiSoftr - Taxi Booking & Dispatch Software 1.0
VisualNEO for Windows 18.08.31
AnyMap JS Maps 8.4.0
ODBC Driver for MailChimp 1.3
OrgChart JS 3.0.7
AnyStock Stock and Financial JS Charts 8.4.0
Top Code
SQL to Java Code Generator 2.6.7
luxSQL 1.0
Ping Pong Game Code Script 1.1
Dansie Shopping Cart Mall Version
Ozone - Java OODBMS 1.2.1.beta
RabbitBB - Online Web Storage Project 20060513
PHP Choral Music Library 1.5
Top Rated
Output Messenger 1.8.0
Aliexpress Clone- Ec21 Script 1
Indiegogo Clone 3.0
Advanced MLM Software 1.2
Online Food Ordeing System 1.0
PHP Image Resize Script 1.0
Best Spotify Clone 1.0
Get Random Record Based on Weight 1.0.0
PHP Point of sale 10.0
Travel Portal Script 9.29
Excel Add-in for Bigcommerce 1.6
Magento Product Designer 1.0
OFOS - Just Eat Clone Script 1.0
PrestaShop Upload Images Module 1.2.1
Trading Software 1.2.4
Shuffle (Sripts) 1.0
File ID: 85036






Shuffle (Sripts) 1.0
Download Shuffle (Sripts) 1.0http://www.mathworks.comReport Error Link
License: Shareware
File Size: 20.5 KB
Downloads: 12
Submit Rating:
Shuffle (Sripts) 1.0 Description
Description: Shuffle - Random permutation of array elements

This function is equivalent to X(RANDPERM(LENGTH(X)), but 50% to 85% faster. It uses D.E. Knuth's shuffle algorithm (also called Fisher-Yates) and the cute KISS random number generator (G. Marsaglia). While RANDPERM needs 2*LENGTH(X)*8 bytes as temporary memory, SHUFFLE needs just a fixed small number of bytes.

1. Inplace shuffling: Y = Shuffle(X, Dim)
INPUT:
X: DOUBLE, SINGLE, CHAR, LOGICAL, (U)INT64/32/16/8 array.
Dim: Dimension to operate on. Optional, default: 1st non-singleton dimension.
OUTPUT:
Y: Array of same type and size as X with shuffled elements.

2. Create a shuffle index: Index = Shuffle(N, 'index', NOut)
This is equivalent to Matlab's RANDPERM, but much faster, if N is large and NOut is small.
INPUT:
N: Integer number.
NOut: The number of output elements. Optional, default: N.
OUTPUT:
Index: [1:NOut] elements of shuffled [1:N] vector in the smallest possible integer type.

3. Derangement index:
Index = Shuffle(N, 'derange', NOut)
Equivalent to the index method, but all Index[i] ~= i. A rejection method is used: Create an index vector until a derangement is gained.

EXAMPLES:
R = Shuffle(1:8) % [8, 1, 2, 6, 4, 3, 5, 7]
R = Shuffle('abcdefg') % 'efbadcg'
R = Shuffle([1:4; 5:8], 2) % [3, 2, 1, 4; 6, 8, 7, 5]
I = Shuffle(8, 'index'); % UINT8([1, 5, 7, 6, 2, 3, 4, 8])
Choose 10 different rows from a 1000 x 100 matrix:
X = rand(1000, 100); Y = X(Shuffle(1000, 'index', 10), :);
Operate on cells or complex arrays:
C = {9, 's', 1:5}; SC = C(Shuffle(numel(C), 'index'));
M = rand(3) + i * rand(3); SM = M(:, Shuffle(size(C, 2), 'index'))

NOTES: There are several other shuffle functions in the FEX. Some use Knuth's method also, some call RANDPERM. This implementation is faster due to calling a compiled MEX file and it has a smaller memory footprint. The KISS random numbers are much better than the RAND() of the C-standard libs.

Run the unit-test TestShuffle to test validity and speed (see screenshot).
Tested: Matlab 6.5, 7.7, 7.8, 32bit, WinXP,
Compiler: LCC 2.4/3.8, BCC 5.5, Open Watcom 1.8, MSVC 2008.
Compatibility to 64 bit, Linux and Mac is assumed.
Pre-compiled Mex: http://www.n-simon.de/mex

License: Shareware

Related: Matrix, rand, choose, shuffle, uint, xshuffle, operate, cshufflenumelc

O/S:BSD, Linux, Solaris, Mac OS X

File Size: 20.5 KB

Downloads: 12



More Similar Code

You can shuffle your photo/image around and bring each photo into view using shuffle effect. Creation of beautiful image slideshows is possible with this script. Downloadable, simple and easy to use script.



Simple Shuffle Transition Effect Slideshow Script using JQuery. Give beautiful shuffle effect to your images using this script.



This recipe solves the problem of shuffle-merging files -- interlacing (shuffle-merging) many small text files into one large text file, while preserving the order of the lines from within the small files.



Randomly shuffle elements of an array



Shuffle feature implemented, up & down buttons added.



The sripts may be included in a website to offer the oportunity to chat with a visitor, to send him to selected pages. Using phrases speeds up communication.



This Flash effect will "shuffle" each of your messages letters. You can set texts, text colors, fonts, font sizes and font alignment. You can set the delay for the appearance between letters. A background image can be added.



You can shuffle your photo/image around and bring each photo into view using shuffle effect. Creation of beautiful image slideshows is possible with this script. Downloadable, simple and easy to use script



A quick and simple solution for creating an online quiz. It supports unlimited questions, choices, quizzes and the ability to randomly shuffle questions and choices.



This is a JavaScript puzzle game in which you have to shuffle first the number s from 1 to 15 by clicking on the shuffle button and then restore the original order from 1 to 15 with the empty square in the lower right corner. This fits inside of a...

User Review for Shuffle (Sripts)
- required fields
     

Please enter text on the image