Custom Sound Randomizing

My friend owns a server and is trying to make custom sounds for a gun that are randomized so its not the same sounds every time you fire the gun

He tried using tables but someone said that it won’t work if this is the entire table (http://puu.sh/4wYFX.txt)

Any ideas on how to do it?

Just use table.Random. Here’s a code I did for a dubstep deagle.


function SWEP:PrimaryAttack(worldsnd)

   self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
   self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
   
   
   if not self:CanPrimaryAttack() then return end

   if not worldsnd then
      if self.PlayingFire then self.PlayingFire:Stop() self.PlayingFire = nil end
	  
      self.PlayingFire = CreateSound( self, table.Random(self.RandomSounds) )
	  if self.PlayingFire then
         self.PlayingFire:Play()
		 self.PlayingFire:ChangeVolume(1,0)
	  end
	  --self.Weapon:EmitSound( table.Random(self.RandomSounds), self.Primary.SoundLevel )
   elseif SERVER then
      if self.PlayingFire then self.PlayingFire:Stop() self.PlayingFire = nil end
	  
      self.PlayingFire = CreateSound( self, table.Random(self.RandomSounds) )
	  if self.PlayingFire then
         self.PlayingFire:Play()
		 self.PlayingFire:ChangeVolume(1,0)
	  end
	  --sound.Play(self.RandomSounds, self:GetPos(), self.Primary.SoundLevel or 75, 100, ThemeDay.WepSoundLevel )
   end
   if ThemeDay and ThemeDay.ShootEffect then ThemeDay.ShootEffect( self.Owner, self, worldsnd ) end

   self:ShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self:GetPrimaryCone() )

   self:TakePrimaryAmmo( 1 )

   local owner = self.Owner
   if not IsValid(owner) or owner:IsNPC() or (not owner.ViewPunch) then return end

   owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
end

SWEP.RandomSounds = {
   Sound( "dubstep/deagle/deagleBRAIN.wav" ),
   Sound( "dubstep/deagle/deagleN4kill.wav" ),
   Sound( "dubstep/deagle/deagleNOISE.wav" ),
   Sound( "dubstep/deagle/deaglePon3.wav" )
}

Edit:

Ignore the theme day part, was something I had for my server.