Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

to not make a random number appear twice

timer random number

  • Please log in to reply
2 replies to this topic

#1 Darkyere


    CC Newcomer

  • Just Joined
  • PipPip
  • 13 posts

Posted 19 November 2008 - 01:00 PM

I have made this application where theres a tlistview whit image destinations in it.

Then i got a timer to shift the picture.

then ive addet a random function to shuffle through the picture.

now what i want to happen is that the same picture dont get shown twice.

So what i tried was to put the number of the picture in another tlistview and make a "While do" to check if randomly generated number is shown in the list.

this is the code ive tried using.
		    randomnr := random(listview1.Items.Count -1);
		    x := 0;

                    While x<listview2.Items.Count - 1 do

                        if listview2.Items[x].Caption = inttostr(randomnr) then

                            randomnr := random(listview1.Items.Count -1);

                            x := 0;


                        x := x +1;


            item := listview1.Items[randomnr];

            listview2.Items.Add.Caption :=  inttostr(randomnr);

This is how the form looks like
img.photobucket.com /albums/ v291/ Rambus666/ Programmering/ MultipleFilesDialog.jpg

All help is apreciatet :)

Best regards,

Edited by WingedPanther, 19 November 2008 - 01:17 PM.
add code tags (the # button)

  • 0

#2 WingedPanther73


    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 19 November 2008 - 01:18 PM

What I would do is have a second listview that is hidden and shift the items from the one you are searching on to the hidden one. That way, you cannot get the same image twice.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/

#3 jakefrog


    CC Lurker

  • Just Joined
  • Pip
  • 9 posts

Posted 03 December 2008 - 08:30 AM

You just check if the actual number is in a list or array that you can store a number already found!
  • 0

Also tagged with one or more of these keywords: timer, random number

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download