Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9104477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:52:43+00:00 2026-06-17T01:52:43+00:00

I have a program that displays a bunch of random triangles using Haskell, OpenGL,

  • 0

I have a program that displays a bunch of random triangles using Haskell, OpenGL, and GLUT. However I’d like the random triangles to change every time I click, or something of that nature (not important when they change).

Currently my working code looks like this:

main :: IO ()
main = do
    (pname, _) <- getArgsAndInitialize
    createWindow $ "Haskellisa"
    -- TODO set based on command line args
    windowSize $= (Size 640 480)
    blend $= Enabled
    blendFunc $= (SrcAlpha, OneMinusSrcAlpha)
    displayCallback $= display
    keyboardMouseCallback $= Just (keyboardMouse)
    mainLoop

display :: IO ()
display = do
    clear [ ColorBuffer ]
    gen0 <- getStdGen
    let (tris,gen1) = randomTris 10 gen0
    let (cols,gen2) = randomColor4s 10 gen1
    let triColPairs = zip tris cols
    mapM_ (\(tri, col) -> drawTri tri col) triColPairs
    flush

However display takes the same StdGen every time by calling getStdGen. What I’d like is for the gen2 from the line let (cols,gen2)... to be used as the generator for the next time, but obviously that requires some sort of mutable state or something of that nature.

What’s the best way to do what I’m asking, such that I will get different randomness every time display runs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:52:44+00:00Added an answer on June 17, 2026 at 1:52 am

    Since you’re in IO anyway, you could just store gen2 via setStdGen:

    setStdGen gen2
    

    so your next round takes off where your previous stopped.

    Another option is to split the StdGen and use one of the results using newStdGen instead of getStdGen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple OpenGL program in C++ that displays a line joining
I have program that has a variable that should never change. However, somehow, it
I have a program that displays and inventory report and i was just wondering
I have a C# program that displays a list of patients with medications where
I have a chat program that displays I list of online users. The message
I have a program that receives webcam video and displays it on a C#
I have a program that occasionally pops up on the screen and displays a
I have a program that displays a table with just 1 Cell row with
I have a program that displays numbers in a System.Windows.Forms.DataGridView . I'm formatting those
I have a program that displays information(simple text, but not in a txt box,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.