Jump to content

can anyone help, how can i do random sentence whitout of repetition of random numbers, sorry about comments its in slovene, tnx


Recommended Posts

Posted

;kreiranje dvodimenzionalne tabele

#include <MsgBoxConstants.au3>   ;klic knjižnice
#include <Array.au3>        ;klicanje knjižnice Array za polja

Loto_generator()        ;ime funkcije

Func Loto_generator()        ;funkcija Loto_generator

   Local $aArray[1][7]        ;definiranje polja-tabele  aArray s 1-no vrstico in 7-imi stolpci
   Local $istevec = 0        ;definiranje števca zaradi izpisa števil

   For $i = 0 To 1        ;za eno vrstico tabele (prvi element vrstice ima vedno oznako 0)

         For $j = 0 To 6        ;za vsak stolpec, od 1 do 7 (prvi element stolpca ima vedno oznako 0)

            $istevilka = Number(Random(1, 39, 1))        ;vrne naključno celo število med 1 in 39 v spremenljivko istevilka s pomočjo Random funkcije
            $aArray[$i][$j] = " " & $istevilka        ;tabela z elementom i,j ki dobi spremenljivko istevilka
            $istevec = $istevec  + 1        ;povečevanje spremenljivke istevec za 1 - zaradi izpisa vrstnega reda izžrebanih števil
            MsgBox(0, "Loto generator", $istevec & ". izžrebana številka je " & $aArray[$i][$j])        ;izpis elementov 1D polja - izžrebanih števil

         Next        ;konec druge for zanke

         MsgBox($MB_SYSTEMMODAL, "Loto kombinacija", "Loto kombinacija izžrebanih števil med 1 in 39" & @CRLF & @CRLF & _ArrayToString($aArray, @TAB, 0, 0, @TAB, 0, 6))        ;izpis celotne tabele - 1D polja izžrebanih števil
         _ArrayDisplay($aArray, "Loto kombinacija izžrebanih števil med 1 in 39")        ;izpis celotne tabele - 1D polja izžrebanih števil

   Next        ;konec prve for zanke

EndFunc   ;konec funkcije Loto_generator

Posted (edited)

Here you go buddy.

 

#include <Array.au3>


$Array = _Loto_Generator(7, 1, 39, 0)
_ArrayDisplay($Array)


;Parameters:
;==============================================
;$pi_HowMuch: How much random numbers you want
;$pi_RangeStart: Lowest possible number
;$pi_RangeEnd: Highest possible number
;$pi_AllowDuplicates:
;       1 - Array can contain the same numbers multiple times
;       0 - Array only contains unique numbers
Func _Loto_Generator($pi_HowMuch, $pi_RangeStart, $pi_RangeEnd, $pi_AllowDuplicates)
    Local $lia_Array[$pi_HowMuch]
    Local $li_Number, $lb_Duplicate

    For $i = 0 To $pi_HowMuch - 1
        $li_Number = Random($pi_RangeStart, $pi_RangeEnd, 1)

        If $pi_AllowDuplicates = 0 Then
            Do
                $lb_Duplicate = False
                $li_Number = Random($pi_RangeStart, $pi_RangeEnd, 1)
                For $j = 0 To $pi_HowMuch - 1
                    If $lia_Array[$j] = $li_Number Then $lb_Duplicate = True
                Next
            Until $lb_Duplicate = False
        EndIf

        $lia_Array[$i]  = $li_Number
    Next

    _ArraySort($lia_Array)
    Return $lia_Array
EndFunc

 

 

Edited by Radiance
Posted

tnx dude :) , have you any idea, how to make this program to display just small and big characters whitout ascii code (91-96) ?

#include <MsgBoxConstants.au3>        

Local $sText = ""        

For $i = 1 To 3        

   $sText &= Chr(Random(65, 122, 1))        

Next       

MsgBox($MB_SYSTEMMODAL, "picking random word", "random word is :" &@TAB & $sText)

Posted (edited)

Look at StringLower() or StringUpper().

The other option is to only use the according ascii code range for lower case (97-122) or upper case (65-90).

Misunderstood the question. Here's what you probably wanted :)

#include <MsgBoxConstants.au3>

Local $sText = ""
Local $iRandom

For $i = 1 To 3
    $iRandom = Random(1, 2, 1)              ;Randomly roll 1 or 2
    If $iRandom = 1 Then                    ;If rolled 1
        $sText &= Chr(Random(65, 90, 1))    ;ASCII range for upper case letters
    Else                                    ;Rolled 2
        $sText &= Chr(Random(97, 122, 1))   ;ASCII range for lower case letters
    EndIf
Next

MsgBox($MB_SYSTEMMODAL, "picking random word", "random word is :" &@TAB & $sText)

 

Edited by Radiance
Posted

i need random in one function whitch peack upper characters(65-90) and lower(97-122) characters, can you made an syntax please

thanks 

Posted

What if you wanted to generate a random word with only the first letter being capital? Would something like this work? (I cannot test atm. :()

#include <MsgBoxConstants.au3>

Local $sText = ""
Local $iRandom

For $i = 1 To 10
    If $i = 1 Then
        $sText &= Chr(Random(65, 90, 1))    ;ASCII range for upper case letters
    Else                                    ;Rolled 2
        $sText &= Chr(Random(97, 122, 1))   ;ASCII range for lower case letters
    EndIf
Next

MsgBox($MB_SYSTEMMODAL, "picking random word", "random word is :" &@TAB & $sText)

Hopefully, this isn't considering hijacking the thread as I do not really have a question; just trying to learn more and more AutoIt! Thanks!

Posted

Or a random name in proper case:

#include <MsgBoxConstants.au3>

Global $sText = ""
Global $iFirst = Random(3,10,1)
Global $iLast = Random(3,10,1)

For $i = 1 To $iFirst + $iLast + 1
    If $i = 1 or $i = $iFirst + 2 Then
        $sText &= Chr(Random(65, 90, 1))    ;ASCII range for upper case letters
    ElseIf $i = $iFirst + 1 Then
        $sText &= " "
    Else
        $sText &= Chr(Random(97, 122, 1))   ;ASCII range for lower case letters
    EndIf
Next

MsgBox($MB_SYSTEMMODAL, "Random Name", "Your random name is:" & @TAB & $sText & @CRLF & "First Name: " & $iFirst & @CRLF & "Last Name: " & $iLast)

I'll be at my main computer shortly to test. :) How would you turn these into random English names, though? Would you just have to create an array with a list of random names, or is there a way to actually do it?

Maybe create two arrays: one containing vowels and one containing consonants and create a little bit of code that grabs from either array based on some sort of pattern?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...