     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

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

window.MaterialsCollectionClass = React.createClass
  getInitialState: ->


window.MaterialsCollection = React.createFactory MaterialsCollectionClass

Portal.renderMaterialsCollection = (collectionId, selectorOrElement, limitOrOptions = Infinity) ->
  # Keep API backward compatible, so accept either 'limit' option as the last argument or hash.
  options = if typeof limitOrOptions == 'number'
              {limit: limitOrOptions}
            else
              limitOrOptions
  React.render MaterialsCollection(collection: collectionId, limit: options.limit, randomize: options.randomize),
    jQuery(selectorOrElement)[0]
