Wonderful! Thanks so much for the prompt response!

On Saturday, August 27, 2016 at 11:03:09 PM UTC-5, joseph ni wrote:
>
> In your Random.map2 you're calling rMines and adding that to your model.
>
> Then you call rTargets, which calls rTargetPoss which calls rMines 
> *again*, this is a independent rMines which gives you another set of 
> results. You use this second rMines to generate the second set of (x, y) 
> which explains why it can repeat your answers.
>
> This is exactly the problem that I was having with my generators. What I 
> ended up doing was having signatures that look like this
> ```
> rTargetPos : Model -> Generator Model
>
> rMine : Model -> Generator Model
>
> ```
>
> and do something like
>
> ```
> constant init 
> `andThen` rMine 
> `andThen` rTargetPos
> ```
>
> This way, you're updating the model and passing that from rMine to 
> rTargetPos.
>
> Here is an example of how I'm doing my generator chaining: 
> https://github.com/mordrax/cotwelm/blob/master/src/Dungeon/Room.elm#L45
>
> Cheers,
> Joe
>
> On Sunday, 28 August 2016 13:16:18 UTC+10, Nate Clark wrote:
>>
>> I think I'm seeing some unusual behavior while generating a random value. 
>> I'm trying to sample multiple (x,y) pairs from a set of available (x,y), 
>> and then sample again from the remaining pairs. The final set (which 
>> shouldn't contain any items from the first set), seemed to contain items 
>> from the first set. So, I added some Debug.log calls in hope of getting a 
>> peek into the random values as they are being generated, and I noticed that 
>> one of the log calls was occurring twice. I've included the log calls and 
>> the console output below.
>>
>>
>> randomGame : Int -> Random.Generator Model
>> randomGame level =
>>     let numTargets = 5 + level
>>         numMines = (25 - numTargets) // 2
>>         rMines = 
>>             allPoss
>>             |> randomPoss numMines 
>>             |> Random.map (log "mines")
>>         
>>         rTargetPoss =
>>             rMines 
>>             |> Random.map (Set.diff allPoss) 
>>             |> Random.map (log "possible target positions")
>>         
>>         rTargets = 
>>             rTargetPoss
>>             `Random.andThen` (randomTargets numTargets)
>>             |> Random.map (log "targets")
>>     in
>>         Random.map2 (\ms ts -> {mines=ms, targets=ts, exposed=Set.empty}) 
>> rMines rTargets
>>         |> Random.map (log "model")
>>
>>
>>
>>
>> <https://lh3.googleusercontent.com/-MTa2mUiWS4c/V8JWkl481MI/AAAAAAAACGk/Zw96lxg4cDU32R3TR_3WQaGpBWTDlUgegCLcB/s1600/Screenshot%2Bfrom%2B2016-08-27%2B22-12-01.png>
>>
>>
>> It logs "mines" twice. The first time seems to be the value that is kept 
>> for the model, but the second "mines" is used to generate the possible 
>> target positions.
>>
>> The full source code (< 350 lines) is at 
>> https://github.com/natec425/Voltorb-Flip/blob/master/game.elm. Any help 
>> would be greatly appreciated.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to