The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## Random function in lua

This is a discussion on Random function in lua within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; hi i am looking for a random function to shuffel my deck of cards. cards are repersented by numbers 1 ...

 Tweet
1. ## Random function in lua

hi

i am looking for a random function to shuffel my deck of cards.
cards are repersented by numbers 1 to 52 which will be stored into an array.
then after the cards have been shuffeled i want to print the array of cards to the screen.

Any one out there can help me.

2. I'll help you out by telling you the random number function.

math.random(10) will return a random number up to 10.
You gotta figure out the rest on your own ;)

3. i know the random function
i dont know how to check for doubles. i might have to loop trough the array to check.
allso how do you print an array of numbers. i know how to print string hardcoded not from a variable.

thanks gary13579

4. Originally Posted by tmaster
i know the random function
i dont know how to check for doubles. i might have to loop trough the array to check.
allso how do you print an array of numbers. i know how to print string hardcoded not from a variable.

thanks gary13579
An array of numbers?
Let's say your array is
Code:
`array = { 0, 3, 5 }`
array[0] is 0, array[1] is 3, array[2] is 5.
So it would be
Code:
`screen:print(x, y, array[0], color)`
This would just print 0 on the screen.
You could also do
Code:
`screen:print(x, y, "The coloum 0 in array is: "..array[0], color)`
This would print "The coloum 0 in array is: 0"

5. thanks gary13579.

6. Yes, you will have to run through your array to check for doubles.

7. i found way to shuffle the 52 integers no need to check for doubles

sorry not indented
function shuffle(carddeck)
local deck ={}
local i
local temp
local temp1
for n = 1,52 do
deck[n] = n
end
for i =0,9 do
for temp = 1,52 do
n = math.random(1,52)
temp1 = deck[temp]
deck[temp] = deck[n]
deck[n] = temp1
end
end
return deck
end

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 11:16 PM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2013, Caputo Media, LLC. All Rights Reserved. Cluster C5.
Contact Us | Free Flash Games | Ad Blockers Suck! Why?