     truncated: true
 
   componentDidMount: ->
+    {randomize} = @props
     jQuery.ajax
       url: Portal.API_V1.MATERIALS_BIN_COLLECTIONS
       data: id: @props.collection
       dataType: 'json'
       success: (data) =>
-        @setState materials: data[0].materials if @isMounted()
+        materials = data[0].materials
+        materials = shuffle(materials) if randomize
+        @setState materials: materials if @isMounted()
 
   toggle: (e) ->
     @setState truncated: not @state.truncated


window.MaterialsCollection = React.createFactory MaterialsCollectionClass

Portal.renderMaterialsCollection = (collectionId, selectorOrElement, limit = Infinity) ->
  React.render MaterialsCollection(collection: collectionId, limit: limit), jQuery(selectorOrElement)[0]

{div, span, a, i} = React.DOM

shuffle = (a) ->
  idx = a.length
  while --idx > 0
    j = ~~(Math.random() * (idx + 1))
    t = a[j]
    a[j] = a[idx]
    a[idx] = t
  a

window.MaterialsCollectionClass = React.createClass
  getInitialState: ->
