Friday, 15 June 2012

VB.net Random Pin Generator Program Overflows -



VB.net Random Pin Generator Program Overflows -

i'm working on random pin generator programme , getting mystery error here upon running it.

shared function createpin() integer dim pin string = "" ' create random id: dim possible string = "0123456789" integer = 0 9 pin += possible.chars(math.floor(rnd() * possible.length) mod possible.length) next homecoming convert.toint32(pin) end function

the error getting overflow! int creating either big or little int. how can happen? no way programme creating int big... although apparently is.

int maximum value 2,147,483,647

your code can generate 9,999,999,999

use long or alter code create sure wont generate number on 2,147,483,647

ex;

function createpin() long dim pin string = "" ' create random id: dim possible string = "0123456789" integer = 0 9 pin += possible.chars(cint(math.floor(rnd() * possible.length) mod possible.length)) next homecoming convert.toint64(pin) end function

and foot note; turn on option explicit on , option strict on

vb.net random

No comments:

Post a Comment