Sign in to follow this  
Followers 0
Rex

Check That Random Don't Gen Same 2 Times In A Row

6 posts in this topic

Hi i created a little script to generate a dinner menu, bu i have one big problem.

Random some times puts uses the same dinner in a row.

#include <GUIConstants.au3>; Includes Gui Constants
#include <file.au3>
#include <string.au3>

Global $Uge

    $Y = 0
    $Uge = "19"
    
    Do
        $Uge = $Uge + 1
        $Y = $Y+1
        If $y = 1 Then
            FileWrite("Menu.txt",">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
            Else
        FileWrite("Menu.txt","" & @CRLF & ">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
        EndIf
        _Retter()
        Until $Y = 4
    Exit

;Funktionen udvælg retter
Func _Retter()
    $i = 0
    $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt")
    Do 
        $i = $i+1
    $Retter = Random(1,$NumberOfLines,1)
    $Read = FileReadLine("Retter.txt", $Retter)
;Checker at den samme ret kommer 2 dage i træk
        If $Read = "chilisuppe" Then
        $i = $i +1
    EndIf
    If $Read = "Pizza" Then
        $i = $i + 1
        EndIf
    FileWrite("Menu.txt", $Read & @CRLF)
Until $i = 7
EndFunc

this i my code, can any one help me to do a check so i dont get the same dinner 2 days in a row

/Rex

Share this post


Link to post
Share on other sites



#include <GUIConstants.au3>; Includes Gui Constants
#include <file.au3>
#include <string.au3>

Global $Uge

    $Y = 0
    $Uge = "19"
    
    Do
        $Uge = $Uge + 1
        $Y = $Y+1
        If $y = 1 Then
            FileWrite("Menu.txt",">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
            Else
        FileWrite("Menu.txt","" & @CRLF & ">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
        EndIf
        _Retter()
        Until $Y = 4
    Exit

;Funktionen udvælg retter
Func _Retter()
    $i = 0
    $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt")
    
    $prev_meal = ""

    Do
        $i = $i+1
        
       ;this loop will prevent 2 of the same meals in a row
         Do
               $Retter = Random(1,$NumberOfLines,1)
               $Read = FileReadLine("Retter.txt", $Retter)
         Until $Read <> $prev_meal

;Checker at den samme ret kommer 2 dage i træk
        If $Read = "chilisuppe" Then
        $i = $i +1
    EndIf
    If $Read = "Pizza" Then
        $i = $i + 1
        EndIf
    FileWrite("Menu.txt", $Read & @CRLF)
  
   ;reacord the meal to check for same meal in next loop iteration
     $prev_meal = $Read

Until $i = 7
EndFunc

I added a nested loop to keep generating random meals until one that doesnt match the previous one is generated.


_____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include <GUIConstants.au3>; Includes Gui Constants
#include <file.au3>
#include <string.au3>

Global $Uge

    $Y = 0
    $Uge = "19"
    
    Do
        $Uge = $Uge + 1
        $Y = $Y+1
        If $y = 1 Then
            FileWrite("Menu.txt",">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
            Else
        FileWrite("Menu.txt","" & @CRLF & ">>>> Menu uge " & $Uge & " <<<<" & @CRLF)
        EndIf
        _Retter()
        Until $Y = 4
    Exit

;Funktionen udvælg retter
Func _Retter()
    $i = 0
    $NumberOfLines = _FileCountLines(@ScriptDir & "\Retter.txt")
    
    $prev_meal = ""

    Do
        $i = $i+1
        
     ;this loop will prevent 2 of the same meals in a row
         Do
               $Retter = Random(1,$NumberOfLines,1)
               $Read = FileReadLine("Retter.txt", $Retter)
         Until $Read <> $prev_meal

;Checker at den samme ret kommer 2 dage i træk
        If $Read = "chilisuppe" Then
        $i = $i +1
    EndIf
    If $Read = "Pizza" Then
        $i = $i + 1
        EndIf
    FileWrite("Menu.txt", $Read & @CRLF)
  
 ;reacord the meal to check for same meal in next loop iteration
     $prev_meal = $Read

Until $i = 7
EndFunc

I added a nested loop to keep generating random meals until one that doesnt match the previous one is generated.

Thx

I'd try to do the same thing, i only forgot to put the "clear" var in the loop (no wondering it dn't work :"> )

Now all i need is to finde out how to put in weekdays then i have a perfect meeal menu creater, and for 4 weeks :(

Ohh any :) on how to prevent getting suppe twice a week ?

/Rex

Edited by Rex

Share this post


Link to post
Share on other sites

Thx

I'd try to do the same thing, i only forgot to put the "clear" var in the loop (no wondering it dn't work :"> )

Now all i need is to finde out how to put in weekdays then i have a perfect meeal menu creater, and for 4 weeks :(

Ohh any :) on how to prevent getting suppe twice a week ?

/Rex

bah. wish i'd thought of something like this 5 years ago. thought i was taking the easy way out by just getting married.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

bah. wish i'd thought of something like this 5 years ago. thought i was taking the easy way out by just getting married.

My prob. is that i'm married - but nither me or my wife can deside what to make for dinner.

/Rex

Share this post


Link to post
Share on other sites

My prob. is that i'm married - but nither me or my wife can deside what to make for dinner.

/Rex

ah. my (soon to be ex) wife can't decide what NOT to have for dinner.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0