Hey @Esha, you can use this code. Let me know if it doesn't work:
from pyspark.sql.functions import rand,when df1 = df.withColumn('isVal', when(rand() > 0.5, 1).otherwise(0))
Hope this helps!
Join Pyspark training online today to know more about Pyspark.
Thanks.