vb.net - Generating Three Unique Random Numbers in Visual Basic? -
i have been working on app lately displays 3 random photos. form consists of 3 pictureboxes , button. when user clicks button, 3 different images shown. problem is, however, these 3 images not unique, of time there doubles , triples too. tried implement function catch succeeded @ lowering chances of identical images. there on 50 images choose from, it's not there isn't enough. here code failed solution came with:
private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click randomimageone() randomimagetwo() randomimagethree() if imagenumber1.text or imagenumber2.text = imagenumber3.text randomimagethree() end if if imagenumber1.text or imagenumber3.text = imagenumber2.text randomimagetwo() end if if imagenumber3.text or imagenumber2.text = imagenumber1.text randomimageone() end if end sub
the 'randomimage' functions generate random number in label (eg. imagenumber1), these numbers correlate number of 1 of 50 images. realize not smartest method, not familiar other way.
i need able either generate 3 unique numbers, don't have worry programming in stop double , triple images, or create solution works 100% of time catch double or triple images.
any appreciated, if explained simply. thank you.
i generate random image 1 , image 2, testing image 2 distinct using while loop. once that done move on generating image three.
information on while loop here.
so in rough code (it's been while since used vba properly):
randomimageone() randomimagetwo() while imagenumber1.text = imagenumber2.text randomimagetwo() loop randomimagethree() while imagenumber3.text = imagenumber2.text or imagenumber3.text = imagenumber1.text randomimagethree() loop
Comments
Post a Comment