Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

using Random command to generate a list of unique digits


  • Please log in to reply
2 replies to this topic
Benny-D
  • Members
  • 1485 posts
  • Last active: Nov 19 2014 02:53 PM
  • Joined: 29 Feb 2008
I don't understand, isn't it like this code should give me a string of ten digits in a random order, each one of which is never repeated in the string?
loop, 10
{
Random, rand , 0, 9
SearchString := "." . rand
IfNotInString, output, rand
output := output . SearchString
}
msgbox, %output%
why do I always get a string here, in which some digits are repeated?

VxE
  • Moderators
  • 3622 posts
  • Last active: Oct 24 2013 04:25 AM
  • Joined: 07 Oct 2006
loop, 10
{
Random, rand , 0, 9
SearchString := "." . rand
IfNotInString, output, [color=red]%[/color]rand[color=red]%[/color]
output := output . SearchString
}
msgbox, %output%
You may consider using InStr() instead of IfInString, simply for consistency.

Benny-D
  • Members
  • 1485 posts
  • Last active: Nov 19 2014 02:53 PM
  • Joined: 29 Feb 2008
Thank you, [VxE]!!!