We devise an algorithm that can incorporate the photomask shape uncertainties in computational lithography such as inverse lithography technique. The photomask patterns are expressed by a random field under a level-set framework to represent the uncertain shape variation. The Karhunen-Loève expansion is introduced so that only several parameters are used to delineate the random field, and thus it can be incorporated into the optimization algorithm in inverse lithography. Simulations show that this method is effective to improve the lithographic imaging performance.