Scatter particle goal across uv's

'''
scatterGoalAcrossUV.py v1.1                                                 
                                                                        
Author: Nate Lang                                                   
web: natelang3d.com

Install: Copy this file into a python shelf button

Use:
Adds new particle attributes and sets the goal attribute
for selected particle system to scatter across the uv's
of the goal object.
'''

from maya import cmds

particleName = cmds.ls(selection=True)

for each in particleName:
    particleShape = cmds.listRelatives(each)
    
    cmds.addAttr(particleShape[0], longName='goalU', dataType='doubleArray')
    cmds.addAttr(particleShape[0], longName='goalU0', dataType='doubleArray')
    cmds.addAttr(particleShape[0], longName='goalV', dataType='doubleArray')
    cmds.addAttr(particleShape[0], longName='goalV0', dataType='doubleArray')
    
    cmds.dynExpression(particleShape[0], creation=True, string=(particleShape[0]+'.goalU = rand(0,1);\n'+particleShape[0]+'.goalV = rand(0,1);'))